diff options
author | Dominik Guzei <dominik.guzei@gmail.com> | 2019-04-12 15:51:57 +0200 |
---|---|---|
committer | Dominik Guzei <dominik.guzei@gmail.com> | 2019-04-12 15:52:55 +0200 |
commit | 76bf7b840ea7d607a21b0294d10be01b26ad0607 (patch) | |
tree | 05b15350fa8cf00972ae8caab812868b9fa9dfe0 /src/features | |
parent | align announcement and spotlight (diff) | |
download | ferdium-app-76bf7b840ea7d607a21b0294d10be01b26ad0607.tar.gz ferdium-app-76bf7b840ea7d607a21b0294d10be01b26ad0607.tar.zst ferdium-app-76bf7b840ea7d607a21b0294d10be01b26ad0607.zip |
merge-in latest develop
Diffstat (limited to 'src/features')
-rw-r--r-- | src/features/announcements/store.js | 14 | ||||
-rw-r--r-- | src/features/utils/ActionBinding.js | 29 | ||||
-rw-r--r-- | src/features/utils/FeatureStore.js | 17 | ||||
-rw-r--r-- | src/features/workspaces/store.js | 20 |
4 files changed, 55 insertions, 25 deletions
diff --git a/src/features/announcements/store.js b/src/features/announcements/store.js index 3c46828bb..b99309ca7 100644 --- a/src/features/announcements/store.js +++ b/src/features/announcements/store.js | |||
@@ -10,6 +10,8 @@ import localStorage from 'mobx-localstorage'; | |||
10 | import { FeatureStore } from '../utils/FeatureStore'; | 10 | import { FeatureStore } from '../utils/FeatureStore'; |
11 | import { getAnnouncementRequest, getChangelogRequest, getCurrentVersionRequest } from './api'; | 11 | import { getAnnouncementRequest, getChangelogRequest, getCurrentVersionRequest } from './api'; |
12 | import { announcementActions } from './actions'; | 12 | import { announcementActions } from './actions'; |
13 | import { createActionBindings } from '../utils/ActionBinding'; | ||
14 | import { createReactions } from '../../stores/lib/Reaction'; | ||
13 | 15 | ||
14 | const LOCAL_STORAGE_KEY = 'announcements'; | 16 | const LOCAL_STORAGE_KEY = 'announcements'; |
15 | 17 | ||
@@ -52,14 +54,15 @@ export class AnnouncementsStore extends FeatureStore { | |||
52 | this.actions = actions; | 54 | this.actions = actions; |
53 | getCurrentVersionRequest.execute(); | 55 | getCurrentVersionRequest.execute(); |
54 | 56 | ||
55 | this._registerActions([ | 57 | this._registerActions(createActionBindings([ |
56 | [announcementActions.show, this._showAnnouncement], | 58 | [announcementActions.show, this._showAnnouncement], |
57 | ]); | 59 | ])); |
58 | 60 | ||
59 | this._registerReactions([ | 61 | this._reactions = createReactions([ |
60 | this._fetchAnnouncements, | 62 | this._fetchAnnouncements, |
61 | this._showAnnouncementToUsersWhoUpdatedApp, | 63 | this._showAnnouncementToUsersWhoUpdatedApp, |
62 | ]); | 64 | ]); |
65 | this._registerReactions(this._reactions); | ||
63 | this.isFeatureActive = true; | 66 | this.isFeatureActive = true; |
64 | } | 67 | } |
65 | 68 | ||
@@ -105,7 +108,6 @@ export class AnnouncementsStore extends FeatureStore { | |||
105 | 108 | ||
106 | _showAnnouncementToUsersWhoUpdatedApp = () => { | 109 | _showAnnouncementToUsersWhoUpdatedApp = () => { |
107 | const { announcement, isNewUser } = this; | 110 | const { announcement, isNewUser } = this; |
108 | console.log(announcement, isNewUser); | ||
109 | // Check if there is an announcement and on't show announcements to new users | 111 | // Check if there is an announcement and on't show announcements to new users |
110 | if (!announcement || isNewUser) return; | 112 | if (!announcement || isNewUser) return; |
111 | 113 | ||
@@ -125,7 +127,7 @@ export class AnnouncementsStore extends FeatureStore { | |||
125 | _fetchAnnouncements = () => { | 127 | _fetchAnnouncements = () => { |
126 | const targetVersion = this.targetVersion || this.currentVersion; | 128 | const targetVersion = this.targetVersion || this.currentVersion; |
127 | if (!targetVersion) return; | 129 | if (!targetVersion) return; |
128 | getChangelogRequest.execute('5.0.1'); | 130 | getChangelogRequest.execute(targetVersion); |
129 | getAnnouncementRequest.execute('5.1.0'); | 131 | getAnnouncementRequest.execute(targetVersion); |
130 | } | 132 | } |
131 | } | 133 | } |
diff --git a/src/features/utils/ActionBinding.js b/src/features/utils/ActionBinding.js new file mode 100644 index 000000000..497aa071b --- /dev/null +++ b/src/features/utils/ActionBinding.js | |||
@@ -0,0 +1,29 @@ | |||
1 | export default class ActionBinding { | ||
2 | action; | ||
3 | |||
4 | isActive = false; | ||
5 | |||
6 | constructor(action) { | ||
7 | this.action = action; | ||
8 | } | ||
9 | |||
10 | start() { | ||
11 | if (!this.isActive) { | ||
12 | const { action } = this; | ||
13 | action[0].listen(action[1]); | ||
14 | this.isActive = true; | ||
15 | } | ||
16 | } | ||
17 | |||
18 | stop() { | ||
19 | if (this.isActive) { | ||
20 | const { action } = this; | ||
21 | action[0].off(action[1]); | ||
22 | this.isActive = false; | ||
23 | } | ||
24 | } | ||
25 | } | ||
26 | |||
27 | export const createActionBindings = actions => ( | ||
28 | actions.map(a => new ActionBinding(a)) | ||
29 | ); | ||
diff --git a/src/features/utils/FeatureStore.js b/src/features/utils/FeatureStore.js index d863f7464..967e745b2 100644 --- a/src/features/utils/FeatureStore.js +++ b/src/features/utils/FeatureStore.js | |||
@@ -1,4 +1,4 @@ | |||
1 | import Reaction from '../../stores/lib/Reaction'; | 1 | import { union } from 'lodash'; |
2 | 2 | ||
3 | export class FeatureStore { | 3 | export class FeatureStore { |
4 | _actions = null; | 4 | _actions = null; |
@@ -13,25 +13,24 @@ export class FeatureStore { | |||
13 | // ACTIONS | 13 | // ACTIONS |
14 | 14 | ||
15 | _registerActions(actions) { | 15 | _registerActions(actions) { |
16 | this._actions = []; | 16 | this._actions = union(this._actions, actions); |
17 | actions.forEach(a => this._actions.push(a)); | 17 | this._startActions(); |
18 | this._startActions(this._actions); | ||
19 | } | 18 | } |
20 | 19 | ||
21 | _startActions(actions = this._actions) { | 20 | _startActions(actions = this._actions) { |
22 | actions.forEach(a => a[0].listen(a[1])); | 21 | console.log(actions); |
22 | actions.forEach(a => a.start()); | ||
23 | } | 23 | } |
24 | 24 | ||
25 | _stopActions(actions = this._actions) { | 25 | _stopActions(actions = this._actions) { |
26 | actions.forEach(a => a[0].off(a[1])); | 26 | actions.forEach(a => a.stop()); |
27 | } | 27 | } |
28 | 28 | ||
29 | // REACTIONS | 29 | // REACTIONS |
30 | 30 | ||
31 | _registerReactions(reactions) { | 31 | _registerReactions(reactions) { |
32 | this._reactions = []; | 32 | this._reactions = union(this._reactions, reactions); |
33 | reactions.forEach(r => this._reactions.push(new Reaction(r))); | 33 | this._startReactions(); |
34 | this._startReactions(this._reactions); | ||
35 | } | 34 | } |
36 | 35 | ||
37 | _startReactions(reactions = this._reactions) { | 36 | _startReactions(reactions = this._reactions) { |
diff --git a/src/features/workspaces/store.js b/src/features/workspaces/store.js index bb18dc182..e11513d1f 100644 --- a/src/features/workspaces/store.js +++ b/src/features/workspaces/store.js | |||
@@ -14,6 +14,8 @@ import { | |||
14 | updateWorkspaceRequest, | 14 | updateWorkspaceRequest, |
15 | } from './api'; | 15 | } from './api'; |
16 | import { WORKSPACES_ROUTES } from './index'; | 16 | import { WORKSPACES_ROUTES } from './index'; |
17 | import { createReactions } from '../../stores/lib/Reaction'; | ||
18 | import { createActionBindings } from '../utils/ActionBinding'; | ||
17 | 19 | ||
18 | const debug = require('debug')('Franz:feature:workspaces:store'); | 20 | const debug = require('debug')('Franz:feature:workspaces:store'); |
19 | 21 | ||
@@ -80,41 +82,39 @@ export default class WorkspacesStore extends FeatureStore { | |||
80 | 82 | ||
81 | // ACTIONS | 83 | // ACTIONS |
82 | 84 | ||
83 | this._freeUserActions = [ | 85 | this._freeUserActions = createActionBindings([ |
84 | [workspaceActions.toggleWorkspaceDrawer, this._toggleWorkspaceDrawer], | 86 | [workspaceActions.toggleWorkspaceDrawer, this._toggleWorkspaceDrawer], |
85 | [workspaceActions.openWorkspaceSettings, this._openWorkspaceSettings], | 87 | [workspaceActions.openWorkspaceSettings, this._openWorkspaceSettings], |
86 | ]; | 88 | ]); |
87 | this._premiumUserActions = [ | 89 | this._premiumUserActions = createActionBindings([ |
88 | [workspaceActions.edit, this._edit], | 90 | [workspaceActions.edit, this._edit], |
89 | [workspaceActions.create, this._create], | 91 | [workspaceActions.create, this._create], |
90 | [workspaceActions.delete, this._delete], | 92 | [workspaceActions.delete, this._delete], |
91 | [workspaceActions.update, this._update], | 93 | [workspaceActions.update, this._update], |
92 | [workspaceActions.activate, this._setActiveWorkspace], | 94 | [workspaceActions.activate, this._setActiveWorkspace], |
93 | [workspaceActions.deactivate, this._deactivateActiveWorkspace], | 95 | [workspaceActions.deactivate, this._deactivateActiveWorkspace], |
94 | ]; | 96 | ]); |
95 | this._allActions = this._freeUserActions.concat(this._premiumUserActions); | 97 | this._allActions = this._freeUserActions.concat(this._premiumUserActions); |
96 | this._registerActions(this._allActions); | 98 | this._registerActions(this._allActions); |
97 | 99 | ||
98 | // REACTIONS | 100 | // REACTIONS |
99 | 101 | ||
100 | this._freeUserReactions = [ | 102 | this._freeUserReactions = createReactions([ |
101 | this._stopPremiumActionsAndReactions, | 103 | this._stopPremiumActionsAndReactions, |
102 | this._openDrawerWithSettingsReaction, | 104 | this._openDrawerWithSettingsReaction, |
103 | this._setFeatureEnabledReaction, | 105 | this._setFeatureEnabledReaction, |
104 | this._setIsPremiumFeatureReaction, | 106 | this._setIsPremiumFeatureReaction, |
105 | this._cleanupInvalidServiceReferences, | 107 | this._cleanupInvalidServiceReferences, |
106 | ]; | 108 | ]); |
107 | this._premiumUserReactions = [ | 109 | this._premiumUserReactions = createReactions([ |
108 | this._setActiveServiceOnWorkspaceSwitchReaction, | 110 | this._setActiveServiceOnWorkspaceSwitchReaction, |
109 | this._activateLastUsedWorkspaceReaction, | 111 | this._activateLastUsedWorkspaceReaction, |
110 | this._setWorkspaceBeingEditedReaction, | 112 | this._setWorkspaceBeingEditedReaction, |
111 | ]; | 113 | ]); |
112 | this._allReactions = this._freeUserReactions.concat(this._premiumUserReactions); | 114 | this._allReactions = this._freeUserReactions.concat(this._premiumUserReactions); |
113 | 115 | ||
114 | this._registerReactions(this._allReactions); | 116 | this._registerReactions(this._allReactions); |
115 | 117 | ||
116 | console.log(this._reactions); | ||
117 | |||
118 | getUserWorkspacesRequest.execute(); | 118 | getUserWorkspacesRequest.execute(); |
119 | this.isFeatureActive = true; | 119 | this.isFeatureActive = true; |
120 | } | 120 | } |