From 052947735bae0f2c5c6876ba60941aa84888576e Mon Sep 17 00:00:00 2001 From: Dominik Guzei Date: Wed, 10 Jul 2019 14:34:30 +0200 Subject: fix reactions and workspace cleanup logic --- src/features/workspaces/store.js | 21 ++++++++++++++------- src/stores/lib/Reaction.js | 6 +++--- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/features/workspaces/store.js b/src/features/workspaces/store.js index 07b16ff23..a82f6895c 100644 --- a/src/features/workspaces/store.js +++ b/src/features/workspaces/store.js @@ -79,7 +79,7 @@ export default class WorkspacesStore extends FeatureStore { // ========== PUBLIC API ========= // - start(stores, actions) { + @action start(stores, actions) { debug('WorkspacesStore::start'); this.stores = stores; this.actions = actions; @@ -104,7 +104,7 @@ export default class WorkspacesStore extends FeatureStore { // REACTIONS this._freeUserReactions = createReactions([ - this._stopPremiumActionsAndReactions, + this._disablePremiumFeatures, this._openDrawerWithSettingsReaction, this._setFeatureEnabledReaction, this._setIsPremiumFeatureReaction, @@ -123,10 +123,7 @@ export default class WorkspacesStore extends FeatureStore { this.isFeatureActive = true; } - stop() { - super.stop(); - debug('WorkspacesStore::stop'); - this.isFeatureActive = false; + @action reset() { this.activeWorkspace = null; this.nextWorkspace = null; this.workspaceBeingEdited = null; @@ -134,6 +131,13 @@ export default class WorkspacesStore extends FeatureStore { this.isWorkspaceDrawerOpen = false; } + @action stop() { + super.stop(); + debug('WorkspacesStore::stop'); + this.reset(); + this.isFeatureActive = false; + } + filterServicesByActiveWorkspace = (services) => { const { activeWorkspace, isFeatureActive } = this; if (isFeatureActive && activeWorkspace) { @@ -281,6 +285,7 @@ export default class WorkspacesStore extends FeatureStore { }; _activateLastUsedWorkspaceReaction = () => { + debug('_activateLastUsedWorkspaceReaction'); if (!this.activeWorkspace && this.userHasWorkspaces) { const { lastActiveWorkspace } = this.settings; if (lastActiveWorkspace) { @@ -324,10 +329,12 @@ export default class WorkspacesStore extends FeatureStore { }); }; - _stopPremiumActionsAndReactions = () => { + _disablePremiumFeatures = () => { if (!this.isUserAllowedToUseFeature) { + debug('_disablePremiumFeatures'); this._stopActions(this._premiumUserActions); this._stopReactions(this._premiumUserReactions); + this.reset(); } else { this._startActions(this._premiumUserActions); this._startReactions(this._premiumUserReactions); diff --git a/src/stores/lib/Reaction.js b/src/stores/lib/Reaction.js index f2642908f..f8009b7f6 100644 --- a/src/stores/lib/Reaction.js +++ b/src/stores/lib/Reaction.js @@ -13,15 +13,15 @@ export default class Reaction { start() { if (!this.isRunning) { - this.dispose = autorun(() => this.reaction()); - this.isActive = true; + this.dispose = autorun(this.reaction); + this.isRunning = true; } } stop() { if (this.isRunning) { this.dispose(); - this.isActive = false; + this.isRunning = false; } } } -- cgit v1.2.3-54-g00ecf