Last active
May 8, 2019 08:10
-
-
Save splincode/1d3594328c893443f4e76fb141dfd73c 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 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