@ngrx/effects
Last updated
Was this helpful?
Last updated
Was this helpful?
Effects are an RxJS powered side effect model for . Effects use streams to provide of actions to reduce state based on external interactions such as network requests, web socket messages and time-based events.
In a service-based Angular application, components are responsible for interacting with external resources directly through services. Instead, effects provide a way to interact with those services and isolate them from the components. Effects are where you handle tasks such as fetching data, long-running tasks that produce multiple events, and other external interactions where your components don't need explicit knowledge of these interactions.
Effects isolate side effects from components, allowing for more pure components that select state and dispatch actions.
Effects are long-running services that listen to an observable of every action dispatched from the .
Effects filter those actions based on the type of action they are interested in. This is done by using an operator.
Effects perform tasks, which are synchronous or asynchronous and return a new action.
npm
For more information on using npm
check out the docs .
yarn
For more information on using yarn
check out the docs .
ng add
ng add
flagsflat - Indicate if a directory is to be created to hold your effects file
skipTests - When true, does not create test files.
group - Group effects file within effects
folder
This command will automate the following steps:
Update package.json
> dependencies
with @ngrx/effects
.
Run npm install
to install those dependencies.
Update your src/app/app.module.ts
> imports
array with EffectsModule.forRoot([AppEffects])
. If you provided flags then the command will attempt to locate and update module found by the flags.
If your project is using the Angular CLI 6+ then you can install the Effects to your project with the following ng add
command :
path - path to the module that you wish to add the import for the to.
project - name of the project defined in your angular.json
to help locating the module to add the to.
module - name of file containing the module that you wish to add the import for the to. Can also include the relative path to the file. For example, src/app/app.module.ts
minimal - By default true, only provide minimal setup for the root effects setup. Only registers in the provided module
with an empty array.