Monitoring Unhandled Actions
We can know if we have dispatched some actions which haven't been handled by any of the NGXS states. This is useful to monitor if we dispatch actions at the right time. For instance, dispatched actions might be coming from the WebSocket, but the action handler is located within the feature state that has not been registered yet. This will let us know that we should either register the state earlier or do anything else from the code perspective because actions are not being handled.
This may be enabled by adding the withNgxsDevelopmentOptions
to provideStore
:
If you are still using modules, include the NgxsDevelopmentModule
plugin in your root app module:
Setting warnOnUnhandledActions
to a truthy value will tell the logger to warn on any unhandled action.
Ignoring Certain Actions
We can ignore specific actions that should not be logged if they have never been handled. For instance, if we're using the @ngxs/router-plugin
and don't care about router actions like RouterNavigation
, then we may add it to the ignore
array:
💡 It's best to import this module only in development mode. This may be achieved using environment imports. See dynamic plugins.
Ignored actions can be also expanded in lazy modules. The @ngxs/store
exposes the NgxsUnhandledActionsLogger
for these purposes:
The ngDevMode
is a specific variable provided by Angular in development mode and by Angular CLI (to Terser) in production mode. This allows tree-shaking NgxsUnhandledActionsLogger
stuff since the NgxsDevelopmentModule
is imported only in development mode. It's never functional in production mode.
Last updated