-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstate.js
executable file
·33 lines (26 loc) · 927 Bytes
/
state.js
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
import {Structure} from 'redux-composite';
let highLevelState = {toggle: false, inc: [1, 2]};
const createStore = () => ({getState: () => highLevelState});
const composite1 = Structure({
toggle: () => {},
inc: [() => {}, () => {}]
});
composite1.createStore({createStore})();
const store1 = composite1.store;
store1.toggle.getState(); // false
store1.inc[0].getState(); // 1
store1.inc[1].getState(); // 2
const composite2 = Structure({
toggle: () => {},
inc: Structure([() => {}, () => {}])
});
composite2.createStore({createStore})();
const store2 = composite2.store;
store2.toggle.getState(); // false
store2.inc.store.getState(); // [1, 2]
store2.inc.structure[0].getState(); // 1
store2.inc.structure[1].getState(); // 2
composite2.getState(); // {toggle: false, inc: [1, 2]}
highLevelState.inc[0] = 3;
store2.inc.structure[0].getState(); // 3
composite2.getState(); // {toggle: false, inc: [3, 2]}