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
| @Effect getUsers$ = this.actions$.pipe( | |
| ofType('GET_USERS', 'CANCEL_GET_USERS'), | |
| withLatestFrom(this.userSelectors.needUsers$), | |
| filter(([action, needUsers]) => needUsers), | |
| map(([action, needUsers]) => action), | |
| switchMap(action => action.type === 'CANCEL_GET_USERS' ? | |
| Observable.of() : | |
| this.getUsers().pipe( | |
| map(users => ({type: 'RECEIVE_USERS', users})), | |
| ), |
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
| @Effect() actionX$ = this.updates$.pipe( | |
| ofType('ACTION_X'), | |
| map(toPayload), | |
| switchMap(payload => this.api.callApiX(payload).pipe( | |
| map(data => ({type: 'ACTION_X_SUCCESS', payload: data})), | |
| catch(err => Observable.of({type: 'ACTION_X_FAIL', payload: err})), | |
| )), | |
| ); | |
| @Effect() actionY$ = this.updates$.pipe( | |
| ofType('ACTION_Y'), |
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
| requireUsers$ = this.userSelectors.needUsers$.pipe( | |
| filter(needUsers => needUsers), | |
| tap(() => this.store.dispatch({type: 'GET_USERS'})), | |
| switchMap(() => this.getUsers()), | |
| tap(users => this.store.dispatch({type: 'RECEIVE_USERS', users})), | |
| finalize(() => this.store.dispatch({type: 'CANCEL_GET_USERS'})), | |
| share(), | |
| ); | |
| users$ = using( |
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
| public muteFirst = <T,R>(first$: Observable<T>, second$: Observable<R>) => Observable.combineLatest( | |
| first$, | |
| second$, | |
| (a,b) => b | |
| ).distinctUntilChanged(); |
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
| ngOnInit() { | |
| this.users$ = this.userService.users$; | |
| } |
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
| requireUsers$ = this.userSelectors.needUsers$.pipe( | |
| filter(needUsers => needUsers), | |
| tap(() => this.store.dispatch({type: 'GET_USERS'})), | |
| switchMap(() => this.getUsers()), | |
| tap(users => this.store.dispatch({type: 'RECEIVE_USERS', users})), | |
| share(), | |
| ); | |
| users$ = using( | |
| () => this.requireUsers$.subscribe(), |
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 function favoriteItemsReducer(state = initialState, action: Action) { | |
| switch(action.type) { | |
| case 'REMOVE_FAVORITE_ITEM': | |
| case 'DELETE_ITEM_SUCCESS': | |
| const itemId = action.payload; | |
| return state.filter(id => id !== itemId); | |
| default: | |
| return state; | |
| } | |
| } |
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, Input} from '@angular/core'; | |
| @Directive({ | |
| selector: '[patchFormGroupValues]', | |
| }) | |
| export class PatchFormGroupValuesDirective { | |
| @Input() formGroup: any; | |
| @Input() | |
| set patchFormGroupValues(val: any) { | |
| if (!val) return; |
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, Input} from '@angular/core'; | |
| import {NgControl} from '@angular/forms'; | |
| @Directive({ | |
| selector: '[setValue]', | |
| }) | |
| export class SetValueDirective { | |
| @Input() | |
| set setValue(val: any) { | |
| this.ngControl.control.setValue(val); |
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, Input} from '@angular/core'; | |
| @Directive({ | |
| selector: '[disableFormGroup]', | |
| }) | |
| export class DisableFormGroupDirective { | |
| @Input() form: any; | |
| @Input() formGroupName: string; | |
| @Input() | |
| set disableFormGroup(disabled: boolean) { |