-
Notifications
You must be signed in to change notification settings - Fork 202
Action sequences return state in a wrong order. #149
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
Comments
To reproduce the issue: With the current order, if you set a break point in Counter.ts you will be able to see that subscribe is called twice. |
Thanks for creating a repository that reproduces this issue, this is odd behavior. I can see the initial call to subscribe getting the correct value, then somehow the stale one gets pushed out again. I'll try and investigate further and see if it's an issue on our end - but I agree with the intended expected behavior, and something weird is going on. |
@pierre-hilt Trying to wrap my head around the source of the issue - I did notice that moving the code that fires a dispatch into Going to dig a bit more and see if I can better understand the why of this though - and see if it's something that can be fixed at the library level, or if just with the way the various lifecycle hooks get fired in angular - that |
ngOnInit() {
this.search$ = this.ngRedux.select(state => state.searchReducer.keyword);
}
ngAfterViewInit() {
this.search$.subscribe((keyword) => {
if (keyword != '') {
this.actions.fetchResultDispatch(keyword.length)
}
});
} |
Hello @e-schultz Thanks a lot helping me on that! Doing the subscribe in ngAfterViewInit, search$.subscribe is done after counter$.subscribe and there is no problem. If you add a setTimeout around counter$.subscribe, it is done after search$.subscribe and so the bug happens. so: More a problem of Observable library? |
Counter.ts ngOnInit() {
this.counter$ = this.ngRedux.select(state => state.searchReducer.total);
window.setTimeout(() => {
this.counter$.subscribe(state =>
this.counter = state)
});
} CounterInfo.ts ngOnInit() {
this.search$ = this.ngRedux.select(state => state.searchReducer.keyword);
}
ngAfterViewInit() {
this.search$.subscribe((keyword) => {
if (keyword != "") {
this.actions.fetchResultDispatch(keyword.length)
}
});
} |
Just adding this to help debug the problem. Simplifying things to just be one component. <p>
Counter: {{ counter }} <br/>
Counter$ Async: {{ counter$ | async }} <br/>
<input id='search-input' type="text" class="search"
[(ngModel)]="keyword" (ngModelChange)="searchKeyword()"/>
</p>
this.counter$ = this.ngRedux.select(state => state.searchReducer.total);
this.search$ = this.ngRedux.select(state => state.searchReducer.keyword);
this.search$.subscribe((keyword) => {
if (keyword != '') {
this.actions.fetchResultDispatch(keyword.length)
}
});
this.counter$.subscribe(state => {
this.counter = state;
});
this.counter$ = this.ngRedux.select(state => state.searchReducer.total);
this.search$ = this.ngRedux.select(state => state.searchReducer.keyword);
this.counter$.subscribe(state => {
this.counter = state;
});
this.search$.subscribe((keyword) => {
if (keyword != '') {
this.actions.fetchResultDispatch(keyword.length)
}
});
When using the redux dev tools, can see that the state has the correct value, also when looking at the logging - nextState is correct. However, for some reason the .select is getting re-triggered with the previous value. .... weird. |
* fix angular-redux#149 - chained actions should not get stale state, changed to create an observable from redux since redux 3.4x supports an observable shim * fix angular-redux#138 - ability to use select decorators in service Changing to use redux's observable, had to change how we created the initial observable. Use switchMap to switch streams once the store observable becomes available
@pierre-hilt I just published 3.2.1-beta.1 which should address the issue. Going to do a bit more testing before doing a non-beta release |
Hey, OK thanks a lot. I will test it on Monday and let you know if I find any bug. |
* fix angular-redux#149 - chained actions should not get stale state, changed to create an observable from redux since redux 3.4x supports an observable shim * fix angular-redux#138 - ability to use select decorators in service Changing to use redux's observable, had to change how we created the initial observable. Use switchMap to switch streams once the store observable becomes available
Hello,
I have some problem with the call orders of Observable.
My case:
I have 2 components, Comp1 and Comp2.
Comp1 is a text search component.
Comp2 is a display of a text.
Comp1 and Comp2 share the same reducer, with the following state:
{ match: number, search_element: string }
Comp1 dispatches Action1 when user enter text in input. Payload is the text and updates search_element.
Comp2 subscribe to search_element. It dispatches Action2 with the number of match in the payload, updates math in the state.
Comp1 subscribe to match.
The problem is subscribe to march is called twice.
First with the value from Comp2 and second from the initial value coming from Action1.
Comp1 displays the wrong match.
I don't understand why subscribe to match is called first with "state2" and then with "state1".
I had to add another flag, search_text_updated, to update match only with state2 value.
Do you have any clue if this is a normal behaviour, for chaining actions?
I will try to create an example to reproduce the issue.
Thanks,
Pierre
The text was updated successfully, but these errors were encountered: