ngrx-workshop
  • Table of Contents
  • Setup and Configuration
  • Rules of Thumb
  • Rules of Thumb pt2
  • NgRx Libraries
    • NgRx Data
    • NgRx Entity
    • Action Creators
    • NgRx Auto Entity
  • NgRx Facades
    • NgRx Facades
  • Testing
    • Testing Factory
    • Testing Reducers
    • Testing Selectors
    • Testing Effects
  • Advanced Actions
    • 3 Types of Actions
    • Deciders
    • Splitter Actions
    • Aggregators
  • ToDo
    • Todo
Powered by GitBook
On this page

Was this helpful?

  1. Advanced Actions

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

@Effect()
 save = this.actions$.pipe(
   ofType<SaveUser>(UserActionTypes.SaveUser),
   map(action => {
     if (action.payload.user.id > 0) {
       return new UpdateUser(action.payload);
     } else {
       return new InsertUser(action.payload);
     }
   })
 );
// Effect store based decider
 @Effect()
 save = this.actions$.pipe(
   ofType<LoadUserById>(UserActionTypes.SaveUser),
   withLatestFrom(this.store.pipe(select(getSelectedUserId))),
     map(([action, userId]) => {
       if (userId > 0) {
         return new UpdateUser(action.payload);
       } else {         
         return new InsertUser(action.payload);
       }
     }));
Previous3 Types of ActionsNextSplitter Actions

Last updated 5 years ago

Was this helpful?