'How can I listen to multple actions in NGXS?
I'm in the process of converting an application from NgRX to NgXs. In NgRx, I could 'listen' to multiple actions in an effect and react appropriately to them. How can I accomplish this using NgXS?
In NgRx, I may have something like the following in an effect
this.actions$.pipe(
ofType(fromCustomers.pageLoaded),
ofType(fromCustomers.pageRefreshed)
)
I see in NgXs that the @Action decorator can accept and array of action types, but I'm confused on how get the value from the multiple action types when delcaring the method.
Solution 1:[1]
In NGXS, you can listen to multiple actions via @Action decorator, like the following:
@Action([fromCustomers.pageLoaded, fromCustomers.pageRefreshed])
pageLoadedOrRefreshed(
ctx: StateContext<YOUR_STATE_MODEL>,
payload: fromCustomers.pageLoaded | fromCustomers.pageRefreshed
) {
// do some stuff here...
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Amer |
