Skip to content

Commit 0529477

Browse files
committed
fix reactions and workspace cleanup logic
1 parent 510a428 commit 0529477

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

src/features/workspaces/store.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export default class WorkspacesStore extends FeatureStore {
7979

8080
// ========== PUBLIC API ========= //
8181

82-
start(stores, actions) {
82+
@action start(stores, actions) {
8383
debug('WorkspacesStore::start');
8484
this.stores = stores;
8585
this.actions = actions;
@@ -104,7 +104,7 @@ export default class WorkspacesStore extends FeatureStore {
104104
// REACTIONS
105105

106106
this._freeUserReactions = createReactions([
107-
this._stopPremiumActionsAndReactions,
107+
this._disablePremiumFeatures,
108108
this._openDrawerWithSettingsReaction,
109109
this._setFeatureEnabledReaction,
110110
this._setIsPremiumFeatureReaction,
@@ -123,17 +123,21 @@ export default class WorkspacesStore extends FeatureStore {
123123
this.isFeatureActive = true;
124124
}
125125

126-
stop() {
127-
super.stop();
128-
debug('WorkspacesStore::stop');
129-
this.isFeatureActive = false;
126+
@action reset() {
130127
this.activeWorkspace = null;
131128
this.nextWorkspace = null;
132129
this.workspaceBeingEdited = null;
133130
this.isSwitchingWorkspace = false;
134131
this.isWorkspaceDrawerOpen = false;
135132
}
136133

134+
@action stop() {
135+
super.stop();
136+
debug('WorkspacesStore::stop');
137+
this.reset();
138+
this.isFeatureActive = false;
139+
}
140+
137141
filterServicesByActiveWorkspace = (services) => {
138142
const { activeWorkspace, isFeatureActive } = this;
139143
if (isFeatureActive && activeWorkspace) {
@@ -281,6 +285,7 @@ export default class WorkspacesStore extends FeatureStore {
281285
};
282286

283287
_activateLastUsedWorkspaceReaction = () => {
288+
debug('_activateLastUsedWorkspaceReaction');
284289
if (!this.activeWorkspace && this.userHasWorkspaces) {
285290
const { lastActiveWorkspace } = this.settings;
286291
if (lastActiveWorkspace) {
@@ -324,10 +329,12 @@ export default class WorkspacesStore extends FeatureStore {
324329
});
325330
};
326331

327-
_stopPremiumActionsAndReactions = () => {
332+
_disablePremiumFeatures = () => {
328333
if (!this.isUserAllowedToUseFeature) {
334+
debug('_disablePremiumFeatures');
329335
this._stopActions(this._premiumUserActions);
330336
this._stopReactions(this._premiumUserReactions);
337+
this.reset();
331338
} else {
332339
this._startActions(this._premiumUserActions);
333340
this._startReactions(this._premiumUserReactions);

src/stores/lib/Reaction.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ export default class Reaction {
1313

1414
start() {
1515
if (!this.isRunning) {
16-
this.dispose = autorun(() => this.reaction());
17-
this.isActive = true;
16+
this.dispose = autorun(this.reaction);
17+
this.isRunning = true;
1818
}
1919
}
2020

2121
stop() {
2222
if (this.isRunning) {
2323
this.dispose();
24-
this.isActive = false;
24+
this.isRunning = false;
2525
}
2626
}
2727
}

0 commit comments

Comments
 (0)