import { Injectable, Inject, NgModule } from '@angular/core';
import { NgxsPlugin, NGXS_PLUGINS } from '@ngxs/store';
export const NGXS_LOGGER_PLUGIN_OPTIONS = new InjectionToken('NGXS_LOGGER_PLUGIN_OPTIONS');
export class LoggerPlugin implements NgxsPlugin {
constructor(@Inject(NGXS_LOGGER_PLUGIN_OPTIONS) private options: any) {}
handle(state, action, next) {
console.log('Action started!', state);
return next(state, action).pipe(
console.log('Action happened!', result);
export class NgxsLoggerPluginModule {
static forRoot(config?: any): ModuleWithProviders {
ngModule: NgxsLoggerPluginModule,
provide: NGXS_LOGGER_PLUGIN_OPTIONS,