Skip to content

Commit

Permalink
refactor(example): refactor effects ofType (#1462)
Browse files Browse the repository at this point in the history
  • Loading branch information
pimenovoleg authored and brandonroberts committed Dec 12, 2018
1 parent 9b3c75b commit ab494b1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
4 changes: 2 additions & 2 deletions projects/example-app/src/app/auth/effects/auth.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { LogoutConfirmationDialogComponent } from '@example-app/auth/components/
export class AuthEffects {
@Effect()
login$ = this.actions$.pipe(
ofType<LoginPageActions.Login>(LoginPageActions.LoginPageActionTypes.Login),
ofType(LoginPageActions.LoginPageActionTypes.Login),
map(action => action.payload.credentials),
exhaustMap((auth: Credentials) =>
this.authService.login(auth).pipe(
Expand Down Expand Up @@ -65,7 +65,7 @@ export class AuthEffects {
);

constructor(
private actions$: Actions,
private actions$: Actions<LoginPageActions.LoginPageActionsUnion>,
private authService: AuthService,
private router: Router,
private dialog: MatDialog
Expand Down
11 changes: 6 additions & 5 deletions projects/example-app/src/app/books/effects/book.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import {
} from 'rxjs/operators';

import { GoogleBooksService } from '@example-app/core/services/google-books.service';
import { BooksApiActions, FindBookPageActions } from '@example-app/books/actions';
import {
BooksApiActions,
FindBookPageActions,
} from '@example-app/books/actions';
import { Book } from '@example-app/books/models/book';

/**
Expand All @@ -33,9 +36,7 @@ export class BookEffects {
Action
> =>
this.actions$.pipe(
ofType<FindBookPageActions.SearchBooks>(
FindBookPageActions.FindBookPageActionTypes.SearchBooks
),
ofType(FindBookPageActions.FindBookPageActionTypes.SearchBooks),
debounceTime(debounce, scheduler),
map(action => action.payload),
switchMap(query => {
Expand All @@ -57,7 +58,7 @@ export class BookEffects {
);

constructor(
private actions$: Actions,
private actions$: Actions<FindBookPageActions.FindBookPageActionsUnion>,
private googleBooks: GoogleBooksService
) {}
}
15 changes: 8 additions & 7 deletions projects/example-app/src/app/books/effects/collection.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ export class CollectionEffects {

@Effect()
addBookToCollection$: Observable<Action> = this.actions$.pipe(
ofType<SelectedBookPageActions.AddBook>(
SelectedBookPageActions.SelectedBookPageActionTypes.AddBook
),
ofType(SelectedBookPageActions.SelectedBookPageActionTypes.AddBook),
map(action => action.payload),
mergeMap(book =>
this.db.insert('books', [book]).pipe(
Expand All @@ -61,9 +59,7 @@ export class CollectionEffects {

@Effect()
removeBookFromCollection$: Observable<Action> = this.actions$.pipe(
ofType<SelectedBookPageActions.RemoveBook>(
SelectedBookPageActions.SelectedBookPageActionTypes.RemoveBook
),
ofType(SelectedBookPageActions.SelectedBookPageActionTypes.RemoveBook),
map(action => action.payload),
mergeMap(book =>
this.db.executeWrite('books', 'delete', [book.id]).pipe(
Expand All @@ -73,5 +69,10 @@ export class CollectionEffects {
)
);

constructor(private actions$: Actions, private db: Database) {}
constructor(
private actions$: Actions<
SelectedBookPageActions.SelectedBookPageActionsUnion
>,
private db: Database
) {}
}

0 comments on commit ab494b1

Please sign in to comment.