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/workspaces/store.js | 67 ++++++++++++++++++++++++++++++---------- 1 file changed, 50 insertions(+), 17 deletions(-) (limited to 'src/features/workspaces/store.js') diff --git a/src/features/workspaces/store.js b/src/features/workspaces/store.js index 4841a4e08..bb18dc182 100644 --- a/src/features/workspaces/store.js +++ b/src/features/workspaces/store.js @@ -55,32 +55,65 @@ export default class WorkspacesStore extends FeatureStore { return !this.isPremiumUpgradeRequired; } + // ========== PRIVATE PROPERTIES ========= // + + _wasDrawerOpenBeforeSettingsRoute = null; + + _freeUserActions = []; + + _premiumUserActions = []; + + _allActions = []; + + _freeUserReactions = []; + + _premiumUserReactions = []; + + _allReactions = []; + + // ========== PUBLIC API ========= // + start(stores, actions) { debug('WorkspacesStore::start'); this.stores = stores; this.actions = actions; - this._registerActions([ + // ACTIONS + + this._freeUserActions = [ + [workspaceActions.toggleWorkspaceDrawer, this._toggleWorkspaceDrawer], + [workspaceActions.openWorkspaceSettings, this._openWorkspaceSettings], + ]; + this._premiumUserActions = [ [workspaceActions.edit, this._edit], [workspaceActions.create, this._create], [workspaceActions.delete, this._delete], [workspaceActions.update, this._update], [workspaceActions.activate, this._setActiveWorkspace], [workspaceActions.deactivate, this._deactivateActiveWorkspace], - [workspaceActions.toggleWorkspaceDrawer, this._toggleWorkspaceDrawer], - [workspaceActions.openWorkspaceSettings, this._openWorkspaceSettings], - ]); + ]; + this._allActions = this._freeUserActions.concat(this._premiumUserActions); + this._registerActions(this._allActions); - this._registerReactions([ - this._setWorkspaceBeingEditedReaction, - this._setActiveServiceOnWorkspaceSwitchReaction, + // REACTIONS + + this._freeUserReactions = [ + this._stopPremiumActionsAndReactions, + this._openDrawerWithSettingsReaction, this._setFeatureEnabledReaction, this._setIsPremiumFeatureReaction, - this._activateLastUsedWorkspaceReaction, - this._openDrawerWithSettingsReaction, this._cleanupInvalidServiceReferences, - this._disableActionsForFreeUser, - ]); + ]; + this._premiumUserReactions = [ + this._setActiveServiceOnWorkspaceSwitchReaction, + this._activateLastUsedWorkspaceReaction, + this._setWorkspaceBeingEditedReaction, + ]; + this._allReactions = this._freeUserReactions.concat(this._premiumUserReactions); + + this._registerReactions(this._allReactions); + + console.log(this._reactions); getUserWorkspacesRequest.execute(); this.isFeatureActive = true; @@ -110,9 +143,7 @@ export default class WorkspacesStore extends FeatureStore { return workspace.services.map(id => services.one(id)).filter(s => !!s); } - // ========== PRIVATE ========= // - - _wasDrawerOpenBeforeSettingsRoute = null; + // ========== PRIVATE METHODS ========= // _getWorkspaceById = id => this.workspaces.find(w => w.id === id); @@ -280,11 +311,13 @@ export default class WorkspacesStore extends FeatureStore { } }; - _disableActionsForFreeUser = () => { + _stopPremiumActionsAndReactions = () => { if (!this.isUserAllowedToUseFeature) { - this._stopListeningToActions(); + this._stopActions(this._premiumUserActions); + this._stopReactions(this._premiumUserReactions); } else { - this._startListeningToActions(); + this._startActions(this._premiumUserActions); + this._startReactions(this._premiumUserReactions); } } } -- cgit v1.2.3-54-g00ecf