Skip to content

Commit

Permalink
reword Registering Effects
Browse files Browse the repository at this point in the history
  • Loading branch information
timdeschryver committed Dec 6, 2024
1 parent 0b1d481 commit adae29c
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions projects/ngrx.io/content/guide/effects/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,15 +237,17 @@ It's recommended to inject all dependencies as effect function arguments for eas

## Registering Effects

Effect classes and functional effects are registered using the `provideEffects` method.

At the root level, effects are registered in the `providers` array of the application configuration.

<div class="alert is-important">

Registering an effects class multiple times (for example in different lazy loaded features) does not cause the effects to run multiple times.
Effects start running **immediately** after instantiation to ensure they are listening for all relevant actions as soon as possible.
Services used in root-level effects are **not** recommended to be used with services that are used with the `APP_INITIALIZER` token.

</div>

Feature-level effects are registered in the `providers` array of the route config.
The same `provideEffects()` function is used in root-level and feature-level effects.

<code-example header="main.ts">
import { bootstrapApplication } from '@angular/platform-browser';
import { provideStore } from '@ngrx/store';
Expand All @@ -263,17 +265,15 @@ bootstrapApplication(AppComponent, {
});
</code-example>

Feature-level effects are registered in the `providers` array of the route config.
The same `provideEffects()` method is used to register effects for a feature.

<div class="alert is-important">

Effects start running **immediately** after instantiation to ensure they are listening for all relevant actions as soon as possible.
Services used in root-level effects are **not** recommended to be used with services that are used with the `APP_INITIALIZER` token.
Registering an effects class multiple times (for example in different lazy loaded features) does not cause the effects to run multiple times.

</div>

### Using the Standalone API

Feature-level effects are registered in the `providers` array of the route config. The same `provideEffects()` function is used in root-level and feature-level effects.

<code-example header="movie-routes.ts">
import { Route } from '@angular/router';
import { provideEffects } from '@ngrx/effects';
Expand All @@ -291,12 +291,6 @@ export const routes: Route[] = [
];
</code-example>

<div class="alert is-important">

**Note:** Registering an effects class multiple times, either by `forRoot()`, `forFeature()`, or `provideEffects()`, (for example in different lazy loaded features) will not cause the effects to run multiple times. There is no functional difference between effects loaded by `root` and `feature`; the important difference between the functions is that `root` providers sets up the providers required for effects.

</div>

### Alternative Way of Registering Effects

You can provide root-/feature-level effects with the provider `USER_PROVIDED_EFFECTS`.
Expand Down

0 comments on commit adae29c

Please sign in to comment.