Dispatch decorator

Reusable logic for avoiding Store injection

Build Statusarrow-up-right Build statusarrow-up-right NPMarrow-up-right Licensearrow-up-right Codacy Badgearrow-up-right Greenkeeper badgearrow-up-right

This package simplifies dispatching process, you shouldn't care about Store service injection as we provide more declarative way to dispatch events out of the box.

📦 Install

To install @ngxs-labs/dispatch-decorator run the following command:

🔨 Usage

Import the module into your root application module:

Dispatch

@Dispatch() is a function that allows you to decorate methods and properties of your components, basically arrow functions are properties. Firstly you have to create a state:

Register this state in NgxsModule and import this state and actions in your component:

Also, your dispatchers can be asynchronous, they can return Promise or Observable, asynchronous operations are handled outside Angular's zone, thus it doesn't affect performance:

Notice that it doesn't matter if you use an arrow function or a normal class method.

Dispatching multiple events

Your dispatchers can also return arrays with events inside:

Last updated