Search code examples
ngxs

NGXS - action interceptors


Is it possible to intercept/preprocess actions before they will be processed by the state? Thought I could achieve this with action handlers

The action handler is an Observable that receives all the actions dispatched before the state takes any action on it.

https://ngxs.gitbook.io/ngxs/advanced/action-handlers

But looks like action handlers (including 'dispatched') are invoked after @Action methods actually.


Solution

  • If the action stream is not providing what you need, and if you want to intercept all actions prior to them being processed you could consider writing a NGXS Plugin.

    The NGXS source for the LoggerPluginModule is pretty simple if you are looking for an example of a plugin.