Skip to content

Instantly share code, notes, and snippets.

@splincode
Last active May 8, 2019 08:14
Show Gist options
  • Save splincode/8567c88f1758794ff926860aa1044b1f to your computer and use it in GitHub Desktop.
Save splincode/8567c88f1758794ff926860aa1044b1f to your computer and use it in GitHub Desktop.
@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