Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(effects): tidy examples in effects lifecycle guide #2336

Merged
merged 2 commits into from
Feb 8, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 15 additions & 17 deletions projects/ngrx.io/content/guide/effects/lifecycle.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Usage:

<code-example header="log.effects.ts">
import { Injectable } from '@angular/core';
import { Actions, Effect, ofType } from '@ngrx/effects';
import { Actions, createEffect } from '@ngrx/effects';
import { tap } from 'rxjs/operators';

@Injectable()
Expand Down Expand Up @@ -64,7 +64,6 @@ import {
LoginPageActions,
AuthApiActions,
} from '../actions';
import { Credentials } from '../models/user';
import { AuthService } from '../services/auth.service';

@Injectable()
Expand Down Expand Up @@ -100,18 +99,18 @@ This allows you to provide a custom behavior, such as only retrying on
certain "retryable" errors, or with maximum number of retries.

<code-example header="customise-error-handler.effects.ts">
```ts
import { ErrorHandler, NgModule } from '@angular/core';
import { Observable, throwError } from 'rxjs';
import { retryWhen, mergeMap } from 'rxjs/operators';
import { Action } from '@ngrx/store';
import { EffectsModule, EFFECTS_ERROR_HANDLER } from '@ngrx/effects';
import { MovieEffects } from './effects/movie.effects';
import { CustomErrorHandler, isRetryable } from '../custom-error-handler';

export function effectResubscriptionHandler<T extends Action>(
observable$: Observable<T>,
export function effectResubscriptionHandler&gt;T extends Action&lt;(
observable$: Observable&gt;T&lt;,
errorHandler?: CustomErrorHandler
): Observable<T> {
): Observable&gt;T&lt; {
return observable$.pipe(
retryWhen(errors =>
errors.pipe(
Expand Down Expand Up @@ -168,29 +167,28 @@ Usage:

<code-example header="user.effects.ts">
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { exhaustMap, takeUntil, tap } from 'rxjs/operators';
import {
Actions,
Effect,
OnRunEffects,
EffectNotification,
ofType,
createEffect,
} from '@ngrx/effects';
import { Action } from '@ngrx/store';
import { Observable } from 'rxjs';
import { exhaustMap, takeUntil, tap } from 'rxjs/operators';

@Injectable()
export class UserEffects implements OnRunEffects {
constructor(private actions$: Actions) {}

updateUser$ = createEffect(() =>
this.actions$.pipe(
ofType('UPDATE_USER'),
tap(action => {
console.log(action);
})
),
{ dispatch: false });
this.actions$.pipe(
ofType('UPDATE_USER'),
tap(action => {
console.log(action);
})
),
{ dispatch: false });

ngrxOnRunEffects(resolvedEffects$: Observable&lt;EffectNotification&gt;) {
return this.actions$.pipe(
Expand Down