Last active
May 8, 2019 08:14
-
-
Save splincode/8567c88f1758794ff926860aa1044b1f 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: ['leaves', 'bark'], | |
name: 'zebra' | |
}, | |
panda: { | |
food: [], | |
name: 'panda' | |
} | |
} | |
}) | |
export class AnimalState { | |
@Selector() | |
public static zebraFood(state: AnimalsStateModel): string[] { | |
const zebraFood = [...state.zebra.food]; | |
zebraFood.reverse(); | |
} | |
@Action(Add) | |
public add({ setState }: StateContext<AnimalsStateModel>, { payload }: Add) { | |
setState((state: AnimalsStateModel) => ({ | |
...state, | |
zebra: { | |
...state.zebra, | |
food: [ ...state.zebra.food, payload ] | |
} | |
})); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment