Created
May 8, 2019 08:20
-
-
Save splincode/503fece96dc61b94e4f89b04f5a7a2af to your computer and use it in GitHub Desktop.
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
@State<AnimalsStateModel>({ | |
name: 'animals', | |
defaults: { | |
zebra: { | |
food: [], | |
name: 'zebra' | |
}, | |
panda: { | |
food: [], | |
name: 'panda' | |
} | |
} | |
}) | |
export class AnimalState { | |
@Selector() | |
@ImmutableSelector() | |
public static zebraFood(state: AnimalsStateModel): string[] { | |
return state.zebra.food.reverse(); | |
} | |
@Action(Add) | |
@ImmutableContext() | |
public Add({ setState }: StateContext<AnimalsStateModel>, { payload }: Add): void { | |
setState((state: AnimalsStateModel) => ({ | |
state.zebra.food.push(payload); | |
return state; | |
})); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment