aboutsummaryrefslogtreecommitdiffstats
path: root/src/features/utils
diff options
context:
space:
mode:
authorLibravatar Dominik Guzei <dominik.guzei@gmail.com>2019-04-12 15:51:57 +0200
committerLibravatar Dominik Guzei <dominik.guzei@gmail.com>2019-04-12 15:52:55 +0200
commit76bf7b840ea7d607a21b0294d10be01b26ad0607 (patch)
tree05b15350fa8cf00972ae8caab812868b9fa9dfe0 /src/features/utils
parentalign announcement and spotlight (diff)
downloadferdium-app-76bf7b840ea7d607a21b0294d10be01b26ad0607.tar.gz
ferdium-app-76bf7b840ea7d607a21b0294d10be01b26ad0607.tar.zst
ferdium-app-76bf7b840ea7d607a21b0294d10be01b26ad0607.zip
merge-in latest develop
Diffstat (limited to 'src/features/utils')
-rw-r--r--src/features/utils/ActionBinding.js29
-rw-r--r--src/features/utils/FeatureStore.js17
2 files changed, 37 insertions, 9 deletions
diff --git a/src/features/utils/ActionBinding.js b/src/features/utils/ActionBinding.js
new file mode 100644
index 000000000..497aa071b
--- /dev/null
+++ b/src/features/utils/ActionBinding.js
@@ -0,0 +1,29 @@
1export default class ActionBinding {
2 action;
3
4 isActive = false;
5
6 constructor(action) {
7 this.action = action;
8 }
9
10 start() {
11 if (!this.isActive) {
12 const { action } = this;
13 action[0].listen(action[1]);
14 this.isActive = true;
15 }
16 }
17
18 stop() {
19 if (this.isActive) {
20 const { action } = this;
21 action[0].off(action[1]);
22 this.isActive = false;
23 }
24 }
25}
26
27export const createActionBindings = actions => (
28 actions.map(a => new ActionBinding(a))
29);
diff --git a/src/features/utils/FeatureStore.js b/src/features/utils/FeatureStore.js
index d863f7464..967e745b2 100644
--- a/src/features/utils/FeatureStore.js
+++ b/src/features/utils/FeatureStore.js
@@ -1,4 +1,4 @@
1import Reaction from '../../stores/lib/Reaction'; 1import { union } from 'lodash';
2 2
3export class FeatureStore { 3export class FeatureStore {
4 _actions = null; 4 _actions = null;
@@ -13,25 +13,24 @@ export class FeatureStore {
13 // ACTIONS 13 // ACTIONS
14 14
15 _registerActions(actions) { 15 _registerActions(actions) {
16 this._actions = []; 16 this._actions = union(this._actions, actions);
17 actions.forEach(a => this._actions.push(a)); 17 this._startActions();
18 this._startActions(this._actions);
19 } 18 }
20 19
21 _startActions(actions = this._actions) { 20 _startActions(actions = this._actions) {
22 actions.forEach(a => a[0].listen(a[1])); 21 console.log(actions);
22 actions.forEach(a => a.start());
23 } 23 }
24 24
25 _stopActions(actions = this._actions) { 25 _stopActions(actions = this._actions) {
26 actions.forEach(a => a[0].off(a[1])); 26 actions.forEach(a => a.stop());
27 } 27 }
28 28
29 // REACTIONS 29 // REACTIONS
30 30
31 _registerReactions(reactions) { 31 _registerReactions(reactions) {
32 this._reactions = []; 32 this._reactions = union(this._reactions, reactions);
33 reactions.forEach(r => this._reactions.push(new Reaction(r))); 33 this._startReactions();
34 this._startReactions(this._reactions);
35 } 34 }
36 35
37 _startReactions(reactions = this._reactions) { 36 _startReactions(reactions = this._reactions) {