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