-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainStore.ts
More file actions
45 lines (40 loc) · 1.05 KB
/
mainStore.ts
File metadata and controls
45 lines (40 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright (c) 2019 Gonzalo Müller Bravo.
// Licensed under the MIT License (MIT), see LICENSE.txt
import {Dispatcher} from 'flux'
import {ReduceStore} from 'flux/utils'
import {ActionType} from './mainActions'
import mainDispatcher from './mainDispatcher'
import MainState from '../MainState'
class MainStore extends ReduceStore<MainState, ActionType> {
constructor(dispatcher: Dispatcher<ActionType>) {
super(dispatcher)
}
getInitialState(): MainState {
return {
isOn: false,
text: 'initial'
}
}
reduce(prevState: MainState, action: ActionType) {
switch (action.type) {
case 'ON':
return {
isOn: true,
text: action.data
}
case 'OFF':
return {
isOn: false,
text: action.data
}
case 'TOGGLE':
return {
isOn: !prevState.isOn,
text: 'toggle'
}
default:
return prevState
}
}
}
export default new MainStore(mainDispatcher)