From 66f52639ef5e850bc71356852b2b5ebc8db1215d Mon Sep 17 00:00:00 2001 From: Giedrius Grabauskas Date: Wed, 25 Nov 2015 02:26:37 +0200 Subject: [PATCH] Added test code --- flux/flux-tests.ts | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/flux/flux-tests.ts b/flux/flux-tests.ts index 52507a2248..c804babd85 100644 --- a/flux/flux-tests.ts +++ b/flux/flux-tests.ts @@ -86,4 +86,41 @@ var customDispatcher = new CustomDispatcher() export = customDispatcher +// Sample Reduce Store +class CounterStore extends ReduceStore { + getInitialState(): number { + return 0; + } + reduce(state: number, action: Object): number { + switch (action.type) { + case 'increment': + return state + 1; + + case 'square': + return state * state; + + default: + return state; + } + } +} + +// Sample Flux container with CounterStore +class CounterContainer extends Component { + static getStores() { + return [CounterStore]; + } + + static calculateState(prevState) { + return { + counter: CounterStore.getState(), + }; + } + + render() { + return {this.state.counter}; + } +} + +const container = Container.create(CounterContainer);