Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Observable updates aren't reflected in templates #112

Open
2 of 9 tasks
paztis opened this issue Feb 19, 2020 · 5 comments
Open
2 of 9 tasks

Observable updates aren't reflected in templates #112

paztis opened this issue Feb 19, 2020 · 5 comments

Comments

@paztis
Copy link

paztis commented Feb 19, 2020

This is a...

  • feature request
  • bug report
  • usage question

What toolchain are you using for transpilation/bundling?

  • @angular/cli
  • Custom @ngTools/webpack
  • Raw ngc
  • SystemJS
  • Rollup
  • Other

Environment

NodeJS Version: 12.13.1
Typescript Version: 3.7.5
Angular Version: 9.0.1
@angular-redux/store version: 10.0.0
@angular/cli version: (if applicable)
rxjs: 6.5.4
OS: Windows

Link to repo showing the issus

(optional, but helps a lot)

Expected Behaviour:

In below sample, redux observable updates are not displayed in the templates.
state.loader.counter is a number that is increased each second.
The console log well display the new value each second.

We only see the first value on the screen

import {Component, OnInit} from '@angular/core';
import {select} from '@angular-redux/store';
import {Observable} from 'rxjs';

@Component({
  selector: 'app-loader',
  template: `<div>Counter: {{ loaderCounter$ | async }}</div>`,
})
export class LoaderComponent implements OnInit {
  ngOnInit() {
    this.loaderCounter$.subscribe((counter) => {
      console.log('----counter', counter)
    })
  }

  @select((state) => {return state.loader.counter}) loaderCounter$: Observable<number>;
}

If I replace the select decorator with a classic selector in the ngOnInit, result is the same

If I put a classic Observable, rendering is working correctly

import {Component, OnInit} from '@angular/core';
import {select} from '@angular-redux/store';
import {Observable} from 'rxjs';

@Component({
  selector: 'app-loader',
  template: `<div>Counter: {{ classicObservable$ | async }}</div>`,
})
export class LoaderComponent implements OnInit {
  ngOnInit() {
  }

  classicObservable$ = new Observable<number>(observer => {
    let counter = 0;
    observer.next(counter);

    setInterval(() => {
      counter++;
      observer.next(counter);
    }, 1000);
  });
}

@paztis
Copy link
Author

paztis commented Feb 20, 2020

I'm using a library that provide an already created redux store
I attached it to my angular app through ngRedux.provideStore(myStore);

But this means there's 2 instances of Redux in my app:

  • 1 provided in the lib I use
  • 1 tracked by @angular-redux/store

Isn't it a conflict here ? I mean angular-redux listen on methods of the bad redux ?
How to support this case ?

@paztis
Copy link
Author

paztis commented Feb 20, 2020

It start to be really crazy.
If I create 2 Observers:

  • 1 from @select as in hte 1st example
  • 1 manual, that subscribe from the select, log and update teh value

Even in this case the rendering is failed...

Noone already envounter this problem ?

import {Component, OnInit} from '@angular/core';
import {select} from '@angular-redux/store';
import {Observable} from 'rxjs';

@Component({
  selector: 'app-loader',
  template: `<div>Counter: {{ classicObservable$ | async }}</div>`,
})
export class LoaderComponent implements OnInit {
  ngOnInit() {
  }

  @select((state) => {return state.loader.counter}) loaderCounter$: Observable<number>;

  classicObservable$ = new Observable<number>(observer => {
    this.loaderCounter$.subscribe((counter) => {
      console.log('----counter', counter)
      observer.next(counter);
    })
  });
}

@paztis
Copy link
Author

paztis commented Feb 20, 2020

OK after loooong search I found the problem, and it seems a pure angular issue

This code is working:

import {Component, OnInit} from '@angular/core';
import {select} from '@angular-redux/store';
import {Observable} from 'rxjs';

@Component({
  selector: 'app-loader',
  template: `<div>Counter: {{ loaderCounter$ | async }}</div>`,
})
export class LoaderComponent implements OnInit {
  ngOnInit() {
        setInterval(() => {
        }, 100)
  }

  @select((state) => {return state.loader.counter}) loaderCounter$: Observable<number>;
}

The reason is that the action origin is out of angular application.
I just create an empty interval method in my component, and the angular application will understand there an activity in the app, then will update corresponding rendering...
Really crazy.

Will open a defect in angular and close this one.

@paztis
Copy link
Author

paztis commented Feb 21, 2020

It seems the reason is I provide to angular-redux an externally created store.
In this case this store is not wrapped by zonejs.
How can we support it properly ?

@maplion
Copy link

maplion commented Feb 23, 2020

@paztis That's quite the journey you had. I think the bigger question is how to get more people managing this repository because it seems pretty dead at the moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants