Skip to content

Instantly share code, notes, and snippets.

@splincode
Last active May 8, 2019 08:10
Show Gist options
  • Save splincode/1d3594328c893443f4e76fb141dfd73c to your computer and use it in GitHub Desktop.
Save splincode/1d3594328c893443f4e76fb141dfd73c 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 AppState {
@Selector()
public static zebraFood(state: AnimalsStateModel): string[] {
const zebraFood = [...state.zebra.food];
zebraFood.reverse();
}
@Action(Add)
public add(ctx: StateContext<AnimalsStateModel>, { payload }: Add): void {
ctx.setState(
patch({
zebra: patch({ food: append([ payload ]) })
})
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment