aboutsummaryrefslogtreecommitdiffstats
path: root/src/features/utils/FeatureStore.js
blob: 48962561de4d557eeeebed2fd44f4ec79c0c4ffc (plain) (blame)
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
import Reaction from '../../stores/lib/Reaction';

export class FeatureStore {
  _actions = null;

  _reactions = null;

  _registerActions(actions) {
    this._actions = [];
    actions.forEach(a => this._actions.push(a));
    this._startListeningToActions();
  }

  _startListeningToActions() {
    this._stopListeningToActions();
    this._actions.forEach(a => a[0].listen(a[1]));
  }

  _stopListeningToActions() {
    this._actions.forEach(a => a[0].off(a[1]));
  }

  _registerReactions(reactions) {
    this._reactions = [];
    reactions.forEach(r => this._reactions.push(new Reaction(r)));
    this._startReactions();
  }

  _startReactions() {
    this._stopReactions();
    this._reactions.forEach(r => r.start());
  }

  _stopReactions() {
    this._reactions.forEach(r => r.stop());
  }

  stop() {
    this._stopListeningToActions();
    this._stopReactions();
  }
}