Skip to content

Instantly share code, notes, and snippets.

@kmaraz
Last active April 10, 2018 21:53
Show Gist options
  • Save kmaraz/9e57b88d0e45d7c53aeadca77f1a04f1 to your computer and use it in GitHub Desktop.
Save kmaraz/9e57b88d0e45d7c53aeadca77f1a04f1 to your computer and use it in GitHub Desktop.
@Injectable()
export class EvnetsEffects implements RegisterEffects {
// Effects would not work by default in the hybrid application,
// therefore we need to preload them during the bootstrap of our app.
// See: app.module.ts and app.effects.ts examples.
@Effect()
deleteEvent$: Observable<EventsActions.All> = this.actions$
.ofType<EventsActions.DeleteEvent>(EventsActions.DELETE_EVENT)
.pipe(
map((action) => action.payload),
switchMap((payload) => this.API.event.delete(payload.eventUuid)
.pipe(
map((data) => new EventsActions.Update(data)),
catchError((error) => of(new EventsActions.UpdateFailed(error)))
))
);
@Effect()
selectEvent$: Observable<EventsActions.All | RouterActions.All> = this.actions$
.ofType<EventsActions.SelectEvent>(EventsActions.SELECT_EVENT)
.pipe(
map((action) => action.payload),
map((payload) => new RouterActions.Go(payload.eventUuid))
);
constructor(
private sources: EffectSources,
private actions$: Actions,
private API: API
) { }
/**
* This method is used to register effects during the Angular bootstrap
* to avoid errors due to unititialized decorators when boostrapping
* the hybrid app.
*/
ngRegisterEffects() {
this.sources.addEffects(this);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment