- Users want to compose reducer tree across modules
- Idea of a single reducer function makes it difficult for the library to dynamically augment the shape of the state tree
- Turning control over to the library to build the root reducer limits the use of meta-reducers
- Feature modules may inadvertently collide with the state of the root module
- Library authors may want to leverage @ngrx/store in their projects and provide an easy way
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export class BookEffects { | |
| @Effect() getOneBook$ = this.actions$.pipe( | |
| ofType(INPUT_ACTION_TYPE), | |
| exhaustMap(action => this.booksService.getOne(action.bookId)), | |
| ); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export class BookEffects { | |
| @Effect() searchBooks$ = this.actions$.pipe( | |
| ofType(INPUT_ACTION_TYPE), | |
| switchMap(action => this.booksService.searchBooks( | |
| action.searchTerm, | |
| )), | |
| ); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export class BookEffects { | |
| @Effect() getAllBooks$ = this.actions$.pipe( | |
| ofType(INPUT_ACTION_TYPE), | |
| exhaustMap(() => this.booksService.getAll()), | |
| ); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export class BookEffects { | |
| @Effect() getAllBooks$ = this.actions$.pipe( | |
| ofType(INPUT_ACTION_TYPE), | |
| switchMap(() => this.booksService.getAll()), | |
| ); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { _throw } from 'rxjs/observable/throw'; | |
| import { of } from 'rxjs/observable/of'; | |
| import { Actions } from '@ngrx/effects'; | |
| class MyEffects { | |
| @Effect() doSomething$ = this.actions$ | |
| .ofType('SOMETHING') | |
| .mergeMap(action => { | |
| return this.http.post('/endpoint') | |
| .mergeMap(result => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Directive, Output, EventEmitter, ChangeDetectionStrategy, ElementRef } from '@angular/core'; | |
| import { Observable } from 'rxjs/Observable'; | |
| import { Subscription } from 'rxjs/Subscription'; | |
| import 'rxjs/add/operator/takeUntil'; | |
| @Directive({ | |
| selector: '[draggable]', | |
| changeDetection: ChangeDetectionStrategy.OnPush | |
| }) | |
| export class DraggableDirective { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { ApolloStore } from 'apollo-client'; | |
| import { Store } from '@ngrx/store'; | |
| import { skip } from 'rxjs/operator/skip'; | |
| import { take } from 'rxjs/operator/take'; | |
| export function toApolloStore(store: Store<any>): ApolloStore { | |
| return { | |
| subscribe(fn: () => void): () => void { | |
| const futureStates$ = skip.call(store, 1); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'rxjs/add/observable/of'; | |
| import { Observable } from 'rxjs/Observable'; | |
| const mockRestService = { | |
| get: jasmine.createSpy('get').and.returnValue(Observable.of({ | |
| })) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { defaultMemoize as memoize } from 'reselect'; | |
| export interface StreamSelector<A,B> { | |
| (input$: Observable<T>): Observable<R>; | |
| } | |
| export interface Share { | |
| <A,B>(): StreamSelector<A,B>; | |
| <A,B,C>(c: C): StreamSelector<A,B>; | |
| <A,B,C,D>(c: C, d: D): StreamSelector<A,B>; |