ngrx-workshop
Search…
Deciders
  • Decides if this effect should process this action (ofType)
  • Can map an action to a different action

Content Deciders

  • Inspect the payload to decide how to process action
  • Can inspect payloads, environmental variables, or store values.
  • Can map an action to a different action based on payload
1
@Effect()
2
save = this.actions$.pipe(
3
ofType<SaveUser>(UserActionTypes.SaveUser),
4
map(action => {
5
if (action.payload.user.id > 0) {
6
return new UpdateUser(action.payload);
7
} else {
8
return new InsertUser(action.payload);
9
}
10
})
11
);
12
Copied!
1
// Effect store based decider
2
@Effect()
3
save = this.actions$.pipe(
4
ofType<LoadUserById>(UserActionTypes.SaveUser),
5
withLatestFrom(this.store.pipe(select(getSelectedUserId))),
6
map(([action, userId]) => {
7
if (userId > 0) {
8
return new UpdateUser(action.payload);
9
} else {
10
return new InsertUser(action.payload);
11
}
12
}));
Copied!
Last modified 2yr ago
Copy link