Introduction
Next let's talk about plugins. Similar to Redux's meta reducers, we have a plugins interface that allows you to build a global plugin for your state.
All you have to do is provide a class to the NGXS_PLUGINS
token. If your plugins have options associated with it, we suggest defining an injection token and then a forRoot
method on your module.
Let's take a look at a basic example of a logger:
You can also use pure functions for plugins. The above example in a pure function would look like this:
NOTE: When providing a pure function make sure to use useValue
instead of useClass
.
To register a plugin with NGXS, import the plugin module in your module and optionally pass in the plugin options like this:
The method also works with forFeature
.
Last updated