aboutsummaryrefslogtreecommitdiffstats
path: root/src/features/utils/FeatureStore.ts
blob: df82a7bd030bec5e9d2034f67e0724fa15d592c7 (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
43
44
45
46
47
48
import type Reaction from '../../stores/lib/Reaction';

export default class FeatureStore {
  _actions: any = [];

  _reactions: Reaction[] = [];

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

  // ACTIONS
  _registerActions(actions) {
    this._actions = actions;
    this._startActions();
  }

  _startActions(actions = this._actions) {
    for (const action of actions) {
      action.start();
    }
  }

  _stopActions(actions = this._actions) {
    for (const action of actions) {
      action.stop();
    }
  }

  // REACTIONS
  _registerReactions(reactions) {
    this._reactions = reactions;
    this._startReactions();
  }

  _startReactions(reactions = this._reactions) {
    for (const reaction of reactions) {
      reaction.start();
    }
  }

  _stopReactions(reactions = this._reactions) {
    for (const reaction of reactions) {
      reaction.stop();
    }
  }
}