I'm using redux in my angular App for weeks now, but I just noticed something about it :
When I'm selecting a part of my store to monitor changes, let's say like that :
In the ngOnInit() of app.component.ts
this.ngRedux.select(s => s.counter).subscribe((counter: number) => {
console.log(counter)
});
The console.log(counter) is executed each time my counter value change, that's ok, that's how it suppose to works.
BUT, the callback is also executed when I first subscribe. So it's like that :
- Enter onNgInit()
- Executing select()
- Executing Subscribe()
- Executing my callback
- ------- Later when counter change : -------
- Executing my callback
My problem is that I dont want my callback to be executed on step 4, because the store did not change !
Is there an issue in my understanding ? Is is supposed to work like that ? If yes : Can I do something to change it ?
Thanks
Unfortunately, this is the standard behaviour of
.subscribe()
. The only thing you can do is to compare your current value ofcounter
with the new one and only react on it if changes happened.