-
Notifications
You must be signed in to change notification settings - Fork 404
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
🐞[BUG]: Dispatch action handler returns after changing the state #1545
Comments
Thank you for reporting this. |
@markwhitfeld I'm trying to implement an undo function. I wanted to save the state before applying the action (since I haven't received an answer on saving just the changes ngxs-labs/immer-adapter#373). Right now I opted to use a plugin, but using the action handler would be much better. |
I also observed similar thing when using ofActionDispatched operator. I was wondering if that is design intended but imo, when action is dispatched, the state shouldn’t change til action is successful. |
I have found myself also needing order-dependant logic. My use case goes as follows: Simplified version of my logic: function build() {
return combineLatest([this.subject$, this.stateObs$]).pipe(
takeUntil(this.actionStream$.pipe(ofActionDispatched(MyAction))),
map(
([val1, val2]) => val1 && val2 ),
);
} In my case, adding a delay and moving operators around like The actual behaviour contradicts with the order of events described in the Action Life-cycle docs |
This is by design. There's no way to make the We would need to re-order observers in the matter they're subscribing to the |
Affected Package
The issue is caused by package @ngxs/store, the Actions class.
Description
According to the docs (https://www.ngxs.io/advanced/action-handlers):
But the actions with status
DISPATCHED
are emitted after the state has already changed.🔬 Minimal Reproduction
https://stackblitz.com/edit/ngxs-simple-demo-fm31wo
I imagined that the state in
state on dispatched action
would show the state before the action is applied.Environment
The text was updated successfully, but these errors were encountered: