diff options
Diffstat (limited to 'src/features')
-rw-r--r-- | src/features/utils/FeatureStore.js | 36 | ||||
-rw-r--r-- | src/features/workspaces/store.js | 67 |
2 files changed, 69 insertions, 34 deletions
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 { | |||
5 | 5 | ||
6 | _reactions = null; | 6 | _reactions = null; |
7 | 7 | ||
8 | stop() { | ||
9 | this._stopActions(); | ||
10 | this._stopReactions(); | ||
11 | } | ||
12 | |||
13 | // ACTIONS | ||
14 | |||
8 | _registerActions(actions) { | 15 | _registerActions(actions) { |
9 | this._actions = []; | 16 | this._actions = []; |
10 | actions.forEach(a => this._actions.push(a)); | 17 | actions.forEach(a => this._actions.push(a)); |
11 | this._startListeningToActions(); | 18 | this._startActions(this._actions); |
12 | } | 19 | } |
13 | 20 | ||
14 | _startListeningToActions() { | 21 | _startActions(actions = this._actions) { |
15 | this._stopListeningToActions(); | 22 | actions.forEach(a => a[0].listen(a[1])); |
16 | this._actions.forEach(a => a[0].listen(a[1])); | ||
17 | } | 23 | } |
18 | 24 | ||
19 | _stopListeningToActions() { | 25 | _stopActions(actions = this._actions) { |
20 | this._actions.forEach(a => a[0].off(a[1])); | 26 | actions.forEach(a => a[0].off(a[1])); |
21 | } | 27 | } |
22 | 28 | ||
29 | // REACTIONS | ||
30 | |||
23 | _registerReactions(reactions) { | 31 | _registerReactions(reactions) { |
24 | this._reactions = []; | 32 | this._reactions = []; |
25 | reactions.forEach(r => this._reactions.push(new Reaction(r))); | 33 | reactions.forEach(r => this._reactions.push(new Reaction(r))); |
26 | this._startReactions(); | 34 | this._startReactions(this._reactions); |
27 | } | 35 | } |
28 | 36 | ||
29 | _startReactions() { | 37 | _startReactions(reactions = this._reactions) { |
30 | this._stopReactions(); | 38 | reactions.forEach(r => r.start()); |
31 | this._reactions.forEach(r => r.start()); | ||
32 | } | ||
33 | |||
34 | _stopReactions() { | ||
35 | this._reactions.forEach(r => r.stop()); | ||
36 | } | 39 | } |
37 | 40 | ||
38 | stop() { | 41 | _stopReactions(reactions = this._reactions) { |
39 | this._stopListeningToActions(); | 42 | reactions.forEach(r => r.stop()); |
40 | this._stopReactions(); | ||
41 | } | 43 | } |
42 | } | 44 | } |
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 | } |