Skip to content

ngxs-labs/action-lifecycle-hooks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

77b7021 · Apr 20, 2023

History

36 Commits
Feb 6, 2023
Feb 6, 2023
Apr 20, 2023
Feb 6, 2023
Dec 19, 2020
Feb 6, 2023
Feb 6, 2023
Dec 19, 2020
Dec 19, 2020
Apr 20, 2023
Apr 20, 2023
Jan 31, 2021
Feb 6, 2023
Feb 6, 2023
Feb 6, 2023
Apr 20, 2023
Feb 6, 2023
Apr 20, 2023

Repository files navigation

npm version


NGXS Action Lifecycle Hooks

Demo

Resources

Description

The Action Lifecycle Hooks facilitates to execute code on action specific lifecycle events such as Completed or Errored. This is is particularly useful when you want to run code on multiple states after an action has completed. Without this plugin you need to inject Actions and listen to the event you are interested. Now, you can use the handy hook to perform the operation.

Quick start

Install the plugin:

  • npm
npm install --save @ngxs-labs/action-lifecycle-hooks
  • yarn
yarn add @ngxs-labs/action-lifecycle-hooks

Next, in your app.module.ts include the plugin.

//...
import { NgxsModule } from '@ngxs/store';
import { NgxsLoggerPluginModule } from '@ngxs/logger-plugin';
import { NgxsActionLifecycleHooksModule } from '@ngxs-labs/action-lifecycle-hooks';

@NgModule({
  declarations: [AppComponent, ListComponent],
  imports: [
    //...
    AngularFireModule.initializeApp(environment.firebase),
    NgxsModule.forRoot(...)
    NgxsLoggerPluginModule.forRoot(),
    NgxsActionLifecycleHooksModule,
  ]
  //...
})
export class AppModule {}

You can now hook into an action lifecycle event like this:

@Action(ActionSuccessful(MyAction))
myActionSuccesful(ctx: StateContext<any>) {
  // run code here
}

@Action(ActionErrored(MyAction))
myActionErrored(ctx: StateContext<any>) {
  // run code here
}

About

NGXS Labs Action Lifecycle Hooks

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published