diff options
Diffstat (limited to 'src/features/utils/FeatureStore.js')
-rw-r--r-- | src/features/utils/FeatureStore.js | 47 |
1 files changed, 33 insertions, 14 deletions
diff --git a/src/features/utils/FeatureStore.js b/src/features/utils/FeatureStore.js index 66b66a104..0bc10e176 100644 --- a/src/features/utils/FeatureStore.js +++ b/src/features/utils/FeatureStore.js | |||
@@ -1,21 +1,40 @@ | |||
1 | import Reaction from '../../stores/lib/Reaction'; | ||
2 | |||
3 | export class FeatureStore { | 1 | export class FeatureStore { |
4 | _actions = null; | 2 | _actions = []; |
3 | |||
4 | _reactions = []; | ||
5 | |||
6 | stop() { | ||
7 | this._stopActions(); | ||
8 | this._stopReactions(); | ||
9 | } | ||
10 | |||
11 | // ACTIONS | ||
12 | |||
13 | _registerActions(actions) { | ||
14 | this._actions = actions; | ||
15 | this._startActions(); | ||
16 | } | ||
5 | 17 | ||
6 | _reactions = null; | 18 | _startActions(actions = this._actions) { |
19 | actions.forEach(a => a.start()); | ||
20 | } | ||
21 | |||
22 | _stopActions(actions = this._actions) { | ||
23 | actions.forEach(a => a.stop()); | ||
24 | } | ||
25 | |||
26 | // REACTIONS | ||
27 | |||
28 | _registerReactions(reactions) { | ||
29 | this._reactions = reactions; | ||
30 | this._startReactions(); | ||
31 | } | ||
7 | 32 | ||
8 | _listenToActions(actions) { | 33 | _startReactions(reactions = this._reactions) { |
9 | if (this._actions) this._actions.forEach(a => a[0].off(a[1])); | 34 | reactions.forEach(r => r.start()); |
10 | this._actions = []; | ||
11 | actions.forEach(a => this._actions.push(a)); | ||
12 | this._actions.forEach(a => a[0].listen(a[1])); | ||
13 | } | 35 | } |
14 | 36 | ||
15 | _startReactions(reactions) { | 37 | _stopReactions(reactions = this._reactions) { |
16 | if (this._reactions) this._reactions.forEach(r => r.stop()); | 38 | reactions.forEach(r => r.stop()); |
17 | this._reactions = []; | ||
18 | reactions.forEach(r => this._reactions.push(new Reaction(r))); | ||
19 | this._reactions.forEach(r => r.start()); | ||
20 | } | 39 | } |
21 | } | 40 | } |