In NgXS i have two ways to trigger an event from a state to another state:
What's the difference between the two ways? Which method is better and why? E.g.
//== state action
@Action()
doAny(context: StateContext<MyContextModel>, payload: any): void {
context.dispatch(new AnotherStateAction());
// this._store.dispatch(new AnotherStateAction()); this code will do the same
}
Docs: https://www.ngxs.io/concepts/state#dispatching-actions-from-actions
As far as I understand, these methods use the same internal method of an InternalStateOperations
service:
StateContextFactory
that creates StateContext
instances.Store
itself.That said, _store
member is apparently treated as private (i.e. API is non-reliable for external use even for state class methods) so I suggest using StateContext
instance for dispatching.