aboutsummaryrefslogtreecommitdiffstats
path: root/src/features/utils/ActionBinding.ts
blob: 787166d440e694352074590a1eed0ebfd709cecb (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
export default class ActionBinding {
  action;

  isActive = false;

  constructor(action) {
    this.action = action;
  }

  start() {
    if (!this.isActive) {
      const { action } = this;
      action[0].listen(action[1]);
      this.isActive = true;
    }
  }

  stop() {
    if (this.isActive) {
      const { action } = this;
      action[0].off(action[1]);
      this.isActive = false;
    }
  }
}

export const createActionBindings = (actions) => (
  actions.map((a) => new ActionBinding(a))
);