Skip to content

Instantly share code, notes, and snippets.

this.store.dispatch({
type: "SAVE_DATA",
payload: data
});
this.saveData(data).pipe( // POST request to server
map(res => this.store.dispatch({type: "DATA_SAVED"})),
).subscribe()
@Effect() saveData$ = this.actions$.pipe(
ofType('SAVE_DATA'),
switchMap(({payload}) => this.saveData(payload)),
map(res => ({type: "DATA_SAVED"})),
);
export interface State {
mediaPlaying: boolean;
audioPlaying: boolean;
videoPlaying: boolean;
}
@Effect() playMediaWithAudio$ = this.actions$.pipe(
ofType("PLAY_AUDIO"),
map(() => ({type: "PLAY_MEDIA"})),
);
audioPlaying$ = this.store.select('audioPlaying');
videoPlaying$ = this.store.select('videoPlaying');
mediaPlaying$ = combineLatest([
this.audioPlaying$,
this.videoPlaying$,
]).pipe(
map(([audioPlaying, videoPlaying]) => audioPlaying || videoPlaying,
);
export interface State {
items: {[index: number]: Item};
favoriteItems: number[];
}
@Effect() this.actions$.pipe(
ofType("DELETE_ITEM_SUCCESS"),
map(() => ({type: "REMOVE_FAVORITE_ITEM_ID"})),
);
ngOnInit() {
this.store.dispatch({type: "GET_USERS"});
}
@Effect getUsers$ = this.actions$.pipe(
ofType('GET_USERS'),
withLatestFrom(this.userSelectors.needUsers$),
filter(([action, needUsers]) => needUsers),
switchMap(() => this.getUsers()),
map(users => ({type: 'RECEIVE_USERS', users})),
);
ngOnDestroy() {
this.store.dispatch({type: "CANCEL_GET_USERS"})
}