diff options
author | Dominik Guzei <dominik.guzei@gmail.com> | 2019-04-12 12:12:25 +0200 |
---|---|---|
committer | Dominik Guzei <dominik.guzei@gmail.com> | 2019-04-12 12:12:25 +0200 |
commit | 70ed64197835377ef701d2ee80830a50cfec93b4 (patch) | |
tree | 30841b41db1670a625cd744adc8b576fe7bc7875 /src/features/workspaces | |
parent | disable autofocus on create workspace input for free users (diff) | |
download | ferdium-app-70ed64197835377ef701d2ee80830a50cfec93b4.tar.gz ferdium-app-70ed64197835377ef701d2ee80830a50cfec93b4.tar.zst ferdium-app-70ed64197835377ef701d2ee80830a50cfec93b4.zip |
improve starting and stopping logic for workspace actions and reactions
Diffstat (limited to 'src/features/workspaces')
-rw-r--r-- | src/features/workspaces/store.js | 67 |
1 files changed, 50 insertions, 17 deletions
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 { | |||
55 | return !this.isPremiumUpgradeRequired; | 55 | return !this.isPremiumUpgradeRequired; |
56 | } | 56 | } |
57 | 57 | ||
58 | // ========== PRIVATE PROPERTIES ========= // | ||
59 | |||
60 | _wasDrawerOpenBeforeSettingsRoute = null; | ||
61 | |||
62 | _freeUserActions = []; | ||
63 | |||
64 | _premiumUserActions = []; | ||
65 | |||
66 | _allActions = []; | ||
67 | |||
68 | _freeUserReactions = []; | ||
69 | |||
70 | _premiumUserReactions = []; | ||
71 | |||
72 | _allReactions = []; | ||
73 | |||
74 | // ========== PUBLIC API ========= // | ||
75 | |||
58 | start(stores, actions) { | 76 | start(stores, actions) { |
59 | debug('WorkspacesStore::start'); | 77 | debug('WorkspacesStore::start'); |
60 | this.stores = stores; | 78 | this.stores = stores; |
61 | this.actions = actions; | 79 | this.actions = actions; |
62 | 80 | ||
63 | this._registerActions([ | 81 | // ACTIONS |
82 | |||
83 | this._freeUserActions = [ | ||
84 | [workspaceActions.toggleWorkspaceDrawer, this._toggleWorkspaceDrawer], | ||
85 | [workspaceActions.openWorkspaceSettings, this._openWorkspaceSettings], | ||
86 | ]; | ||
87 | this._premiumUserActions = [ | ||
64 | [workspaceActions.edit, this._edit], | 88 | [workspaceActions.edit, this._edit], |
65 | [workspaceActions.create, this._create], | 89 | [workspaceActions.create, this._create], |
66 | [workspaceActions.delete, this._delete], | 90 | [workspaceActions.delete, this._delete], |
67 | [workspaceActions.update, this._update], | 91 | [workspaceActions.update, this._update], |
68 | [workspaceActions.activate, this._setActiveWorkspace], | 92 | [workspaceActions.activate, this._setActiveWorkspace], |
69 | [workspaceActions.deactivate, this._deactivateActiveWorkspace], | 93 | [workspaceActions.deactivate, this._deactivateActiveWorkspace], |
70 | [workspaceActions.toggleWorkspaceDrawer, this._toggleWorkspaceDrawer], | 94 | ]; |
71 | [workspaceActions.openWorkspaceSettings, this._openWorkspaceSettings], | 95 | this._allActions = this._freeUserActions.concat(this._premiumUserActions); |
72 | ]); | 96 | this._registerActions(this._allActions); |
73 | 97 | ||
74 | this._registerReactions([ | 98 | // REACTIONS |
75 | this._setWorkspaceBeingEditedReaction, | 99 | |
76 | this._setActiveServiceOnWorkspaceSwitchReaction, | 100 | this._freeUserReactions = [ |
101 | this._stopPremiumActionsAndReactions, | ||
102 | this._openDrawerWithSettingsReaction, | ||
77 | this._setFeatureEnabledReaction, | 103 | this._setFeatureEnabledReaction, |
78 | this._setIsPremiumFeatureReaction, | 104 | this._setIsPremiumFeatureReaction, |
79 | this._activateLastUsedWorkspaceReaction, | ||
80 | this._openDrawerWithSettingsReaction, | ||
81 | this._cleanupInvalidServiceReferences, | 105 | this._cleanupInvalidServiceReferences, |
82 | this._disableActionsForFreeUser, | 106 | ]; |
83 | ]); | 107 | this._premiumUserReactions = [ |
108 | this._setActiveServiceOnWorkspaceSwitchReaction, | ||
109 | this._activateLastUsedWorkspaceReaction, | ||
110 | this._setWorkspaceBeingEditedReaction, | ||
111 | ]; | ||
112 | this._allReactions = this._freeUserReactions.concat(this._premiumUserReactions); | ||
113 | |||
114 | this._registerReactions(this._allReactions); | ||
115 | |||
116 | console.log(this._reactions); | ||
84 | 117 | ||
85 | getUserWorkspacesRequest.execute(); | 118 | getUserWorkspacesRequest.execute(); |
86 | this.isFeatureActive = true; | 119 | this.isFeatureActive = true; |
@@ -110,9 +143,7 @@ export default class WorkspacesStore extends FeatureStore { | |||
110 | return workspace.services.map(id => services.one(id)).filter(s => !!s); | 143 | return workspace.services.map(id => services.one(id)).filter(s => !!s); |
111 | } | 144 | } |
112 | 145 | ||
113 | // ========== PRIVATE ========= // | 146 | // ========== PRIVATE METHODS ========= // |
114 | |||
115 | _wasDrawerOpenBeforeSettingsRoute = null; | ||
116 | 147 | ||
117 | _getWorkspaceById = id => this.workspaces.find(w => w.id === id); | 148 | _getWorkspaceById = id => this.workspaces.find(w => w.id === id); |
118 | 149 | ||
@@ -280,11 +311,13 @@ export default class WorkspacesStore extends FeatureStore { | |||
280 | } | 311 | } |
281 | }; | 312 | }; |
282 | 313 | ||
283 | _disableActionsForFreeUser = () => { | 314 | _stopPremiumActionsAndReactions = () => { |
284 | if (!this.isUserAllowedToUseFeature) { | 315 | if (!this.isUserAllowedToUseFeature) { |
285 | this._stopListeningToActions(); | 316 | this._stopActions(this._premiumUserActions); |
317 | this._stopReactions(this._premiumUserReactions); | ||
286 | } else { | 318 | } else { |
287 | this._startListeningToActions(); | 319 | this._startActions(this._premiumUserActions); |
320 | this._startReactions(this._premiumUserReactions); | ||
288 | } | 321 | } |
289 | } | 322 | } |
290 | } | 323 | } |