Last active
April 6, 2019 19:52
-
-
Save splincode/47e6a6514a449a41033c35020daf45a4 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 { | |
@Mutation() | |
@Action(FeedZebra) | |
public feedZebra(ctx: StateContext<AnimalsStateModel>, { payload }: FeedZebra): AnimalsStateModel { | |
ctx.setState((state: AnimalsStateModel) => { // immutable mutation with immer (analogue produce) | |
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