From 70ed64197835377ef701d2ee80830a50cfec93b4 Mon Sep 17 00:00:00 2001 From: Dominik Guzei Date: Fri, 12 Apr 2019 12:12:25 +0200 Subject: improve starting and stopping logic for workspace actions and reactions --- src/features/utils/FeatureStore.js | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) (limited to 'src/features/utils/FeatureStore.js') diff --git a/src/features/utils/FeatureStore.js b/src/features/utils/FeatureStore.js index 48962561d..d863f7464 100644 --- a/src/features/utils/FeatureStore.js +++ b/src/features/utils/FeatureStore.js @@ -5,38 +5,40 @@ export class FeatureStore { _reactions = null; + stop() { + this._stopActions(); + this._stopReactions(); + } + + // ACTIONS + _registerActions(actions) { this._actions = []; actions.forEach(a => this._actions.push(a)); - this._startListeningToActions(); + this._startActions(this._actions); } - _startListeningToActions() { - this._stopListeningToActions(); - this._actions.forEach(a => a[0].listen(a[1])); + _startActions(actions = this._actions) { + actions.forEach(a => a[0].listen(a[1])); } - _stopListeningToActions() { - this._actions.forEach(a => a[0].off(a[1])); + _stopActions(actions = this._actions) { + actions.forEach(a => a[0].off(a[1])); } + // REACTIONS + _registerReactions(reactions) { this._reactions = []; reactions.forEach(r => this._reactions.push(new Reaction(r))); - this._startReactions(); + this._startReactions(this._reactions); } - _startReactions() { - this._stopReactions(); - this._reactions.forEach(r => r.start()); - } - - _stopReactions() { - this._reactions.forEach(r => r.stop()); + _startReactions(reactions = this._reactions) { + reactions.forEach(r => r.start()); } - stop() { - this._stopListeningToActions(); - this._stopReactions(); + _stopReactions(reactions = this._reactions) { + reactions.forEach(r => r.stop()); } } -- cgit v1.2.3-70-g09d2