diff options
author | Ricardo Cino <ricardo@cino.io> | 2022-07-07 09:31:50 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-07 09:31:50 +0200 |
commit | 71c52373f81cace664047edd19d9d289f45a4dff (patch) | |
tree | 69b3f1d45a8b3f1ceab9497ea3c96e9dc18e3166 /src/stores | |
parent | 6.0.0-nightly.91 [skip ci] (diff) | |
download | ferdium-app-71c52373f81cace664047edd19d9d289f45a4dff.tar.gz ferdium-app-71c52373f81cace664047edd19d9d289f45a4dff.tar.zst ferdium-app-71c52373f81cace664047edd19d9d289f45a4dff.zip |
chore: Mobx & React-Router upgrade (#406)
Co-authored-by: Vijay A <vraravam@users.noreply.github.com>
Diffstat (limited to 'src/stores')
-rw-r--r-- | src/stores/AppStore.ts | 6 | ||||
-rw-r--r-- | src/stores/FeaturesStore.ts | 25 | ||||
-rw-r--r-- | src/stores/GlobalErrorStore.ts | 4 | ||||
-rw-r--r-- | src/stores/RecipePreviewsStore.ts | 5 | ||||
-rw-r--r-- | src/stores/RecipesStore.ts | 4 | ||||
-rw-r--r-- | src/stores/RequestStore.ts | 4 | ||||
-rw-r--r-- | src/stores/ServicesStore.ts | 4 | ||||
-rw-r--r-- | src/stores/SettingsStore.ts | 7 | ||||
-rw-r--r-- | src/stores/UIStore.ts | 5 | ||||
-rw-r--r-- | src/stores/UserStore.ts | 4 | ||||
-rw-r--r-- | src/stores/index.ts | 2 | ||||
-rw-r--r-- | src/stores/lib/Request.js | 4 | ||||
-rw-r--r-- | src/stores/lib/TypedStore.ts | 20 |
13 files changed, 71 insertions, 23 deletions
diff --git a/src/stores/AppStore.ts b/src/stores/AppStore.ts index 0ecfdb7c0..ed6d0e263 100644 --- a/src/stores/AppStore.ts +++ b/src/stores/AppStore.ts | |||
@@ -7,7 +7,7 @@ import { | |||
7 | getCurrentWindow, | 7 | getCurrentWindow, |
8 | process as remoteProcess, | 8 | process as remoteProcess, |
9 | } from '@electron/remote'; | 9 | } from '@electron/remote'; |
10 | import { action, computed, observable } from 'mobx'; | 10 | import { action, computed, makeObservable, observable } from 'mobx'; |
11 | import moment from 'moment'; | 11 | import moment from 'moment'; |
12 | import AutoLaunch from 'auto-launch'; | 12 | import AutoLaunch from 'auto-launch'; |
13 | import ms from 'ms'; | 13 | import ms from 'ms'; |
@@ -105,6 +105,8 @@ export default class AppStore extends TypedStore { | |||
105 | constructor(stores: Stores, api: ApiInterface, actions: Actions) { | 105 | constructor(stores: Stores, api: ApiInterface, actions: Actions) { |
106 | super(stores, api, actions); | 106 | super(stores, api, actions); |
107 | 107 | ||
108 | makeObservable(this); | ||
109 | |||
108 | // Register action handlers | 110 | // Register action handlers |
109 | this.actions.app.notify.listen(this._notify.bind(this)); | 111 | this.actions.app.notify.listen(this._notify.bind(this)); |
110 | this.actions.app.setBadge.listen(this._setBadge.bind(this)); | 112 | this.actions.app.setBadge.listen(this._setBadge.bind(this)); |
@@ -510,7 +512,7 @@ export default class AppStore extends TypedStore { | |||
510 | } | 512 | } |
511 | 513 | ||
512 | _setLocale() { | 514 | _setLocale() { |
513 | if (this.stores.user.isLoggedIn && this.stores.user.data.locale) { | 515 | if (this.stores.user?.isLoggedIn && this.stores.user?.data.locale) { |
514 | this.locale = this.stores.user.data.locale; | 516 | this.locale = this.stores.user.data.locale; |
515 | } else if (!this.locale) { | 517 | } else if (!this.locale) { |
516 | this.locale = this._getDefaultLocale(); | 518 | this.locale = this._getDefaultLocale(); |
diff --git a/src/stores/FeaturesStore.ts b/src/stores/FeaturesStore.ts index b63c252df..ed0c6c17b 100644 --- a/src/stores/FeaturesStore.ts +++ b/src/stores/FeaturesStore.ts | |||
@@ -1,5 +1,14 @@ | |||
1 | import { computed, observable, runInAction } from 'mobx'; | 1 | import { |
2 | action, | ||
3 | computed, | ||
4 | makeObservable, | ||
5 | observable, | ||
6 | runInAction, | ||
7 | } from 'mobx'; | ||
2 | 8 | ||
9 | import { Stores } from '../@types/stores.types'; | ||
10 | import { ApiInterface } from '../api'; | ||
11 | import { Actions } from '../actions/lib/actions'; | ||
3 | import CachedRequest from './lib/CachedRequest'; | 12 | import CachedRequest from './lib/CachedRequest'; |
4 | import serviceProxy from '../features/serviceProxy'; | 13 | import serviceProxy from '../features/serviceProxy'; |
5 | import basicAuth from '../features/basicAuth'; | 14 | import basicAuth from '../features/basicAuth'; |
@@ -24,6 +33,12 @@ export default class FeaturesStore extends TypedStore { | |||
24 | 33 | ||
25 | @observable features = {}; | 34 | @observable features = {}; |
26 | 35 | ||
36 | constructor(stores: Stores, api: ApiInterface, actions: Actions) { | ||
37 | super(stores, api, actions); | ||
38 | |||
39 | makeObservable(this); | ||
40 | } | ||
41 | |||
27 | async setup(): Promise<void> { | 42 | async setup(): Promise<void> { |
28 | this.registerReactions([ | 43 | this.registerReactions([ |
29 | this._updateFeatures, | 44 | this._updateFeatures, |
@@ -49,9 +64,11 @@ export default class FeaturesStore extends TypedStore { | |||
49 | } | 64 | } |
50 | Object.assign(features, requestResult); | 65 | Object.assign(features, requestResult); |
51 | } | 66 | } |
52 | runInAction('FeaturesStore::_updateFeatures', () => { | 67 | runInAction( |
53 | this.features = features; | 68 | action('FeaturesStore::_updateFeatures', () => { |
54 | }); | 69 | this.features = features; |
70 | }), | ||
71 | ); | ||
55 | }; | 72 | }; |
56 | 73 | ||
57 | _monitorLoginStatus(): void { | 74 | _monitorLoginStatus(): void { |
diff --git a/src/stores/GlobalErrorStore.ts b/src/stores/GlobalErrorStore.ts index 8c6317c91..c42e9a4af 100644 --- a/src/stores/GlobalErrorStore.ts +++ b/src/stores/GlobalErrorStore.ts | |||
@@ -1,4 +1,4 @@ | |||
1 | import { observable, action } from 'mobx'; | 1 | import { observable, action, makeObservable } from 'mobx'; |
2 | import { Actions } from '../actions/lib/actions'; | 2 | import { Actions } from '../actions/lib/actions'; |
3 | import { ApiInterface } from '../api'; | 3 | import { ApiInterface } from '../api'; |
4 | import { Stores } from '../@types/stores.types'; | 4 | import { Stores } from '../@types/stores.types'; |
@@ -34,6 +34,8 @@ export default class GlobalErrorStore extends TypedStore { | |||
34 | constructor(stores: Stores, api: ApiInterface, actions: Actions) { | 34 | constructor(stores: Stores, api: ApiInterface, actions: Actions) { |
35 | super(stores, api, actions); | 35 | super(stores, api, actions); |
36 | 36 | ||
37 | makeObservable(this); | ||
38 | |||
37 | window.addEventListener('error', (...errorArgs: any[]): void => { | 39 | window.addEventListener('error', (...errorArgs: any[]): void => { |
38 | // @ts-ignore ts-message: Expected 5 arguments, but got 2. | 40 | // @ts-ignore ts-message: Expected 5 arguments, but got 2. |
39 | this._handleConsoleError.call(this, ['error', ...errorArgs]); | 41 | this._handleConsoleError.call(this, ['error', ...errorArgs]); |
diff --git a/src/stores/RecipePreviewsStore.ts b/src/stores/RecipePreviewsStore.ts index b1d50c8b8..1c95e6b54 100644 --- a/src/stores/RecipePreviewsStore.ts +++ b/src/stores/RecipePreviewsStore.ts | |||
@@ -1,4 +1,5 @@ | |||
1 | import { action, computed, observable } from 'mobx'; | 1 | import { action, computed, makeObservable, observable } from 'mobx'; |
2 | |||
2 | import { Actions } from '../actions/lib/actions'; | 3 | import { Actions } from '../actions/lib/actions'; |
3 | import { ApiInterface } from '../api'; | 4 | import { ApiInterface } from '../api'; |
4 | import Recipe from '../models/Recipe'; | 5 | import Recipe from '../models/Recipe'; |
@@ -28,6 +29,8 @@ export default class RecipePreviewsStore extends TypedStore { | |||
28 | constructor(stores: Stores, api: ApiInterface, actions: Actions) { | 29 | constructor(stores: Stores, api: ApiInterface, actions: Actions) { |
29 | super(stores, api, actions); | 30 | super(stores, api, actions); |
30 | 31 | ||
32 | makeObservable(this); | ||
33 | |||
31 | // Register action handlers | 34 | // Register action handlers |
32 | this.actions.recipePreview.search.listen(this._search.bind(this)); | 35 | this.actions.recipePreview.search.listen(this._search.bind(this)); |
33 | } | 36 | } |
diff --git a/src/stores/RecipesStore.ts b/src/stores/RecipesStore.ts index 364d56dd2..25304e97c 100644 --- a/src/stores/RecipesStore.ts +++ b/src/stores/RecipesStore.ts | |||
@@ -1,4 +1,4 @@ | |||
1 | import { action, computed, observable } from 'mobx'; | 1 | import { action, computed, makeObservable, observable } from 'mobx'; |
2 | import { readJSONSync } from 'fs-extra'; | 2 | import { readJSONSync } from 'fs-extra'; |
3 | import semver from 'semver'; | 3 | import semver from 'semver'; |
4 | 4 | ||
@@ -24,6 +24,8 @@ export default class RecipesStore extends TypedStore { | |||
24 | constructor(stores: Stores, api: ApiInterface, actions: Actions) { | 24 | constructor(stores: Stores, api: ApiInterface, actions: Actions) { |
25 | super(stores, api, actions); | 25 | super(stores, api, actions); |
26 | 26 | ||
27 | makeObservable(this); | ||
28 | |||
27 | // Register action handlers | 29 | // Register action handlers |
28 | this.actions.recipe.install.listen(this._install.bind(this)); | 30 | this.actions.recipe.install.listen(this._install.bind(this)); |
29 | this.actions.recipe.update.listen(this._update.bind(this)); | 31 | this.actions.recipe.update.listen(this._update.bind(this)); |
diff --git a/src/stores/RequestStore.ts b/src/stores/RequestStore.ts index e5df1292d..a964c5d12 100644 --- a/src/stores/RequestStore.ts +++ b/src/stores/RequestStore.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import { ipcRenderer } from 'electron'; | 1 | import { ipcRenderer } from 'electron'; |
2 | import { action, computed, observable } from 'mobx'; | 2 | import { action, computed, makeObservable, observable } from 'mobx'; |
3 | import ms from 'ms'; | 3 | import ms from 'ms'; |
4 | 4 | ||
5 | import { Actions } from '../actions/lib/actions'; | 5 | import { Actions } from '../actions/lib/actions'; |
@@ -28,6 +28,8 @@ export default class RequestStore extends TypedStore { | |||
28 | constructor(stores: Stores, api: ApiInterface, actions: Actions) { | 28 | constructor(stores: Stores, api: ApiInterface, actions: Actions) { |
29 | super(stores, api, actions); | 29 | super(stores, api, actions); |
30 | 30 | ||
31 | makeObservable(this); | ||
32 | |||
31 | this.actions.requests.retryRequiredRequests.listen( | 33 | this.actions.requests.retryRequiredRequests.listen( |
32 | this._retryRequiredRequests.bind(this), | 34 | this._retryRequiredRequests.bind(this), |
33 | ); | 35 | ); |
diff --git a/src/stores/ServicesStore.ts b/src/stores/ServicesStore.ts index 4c1b4116c..7812d5aee 100644 --- a/src/stores/ServicesStore.ts +++ b/src/stores/ServicesStore.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import { shell } from 'electron'; | 1 | import { shell } from 'electron'; |
2 | import { action, reaction, computed, observable } from 'mobx'; | 2 | import { action, reaction, computed, observable, makeObservable } from 'mobx'; |
3 | import { debounce, remove } from 'lodash'; | 3 | import { debounce, remove } from 'lodash'; |
4 | import ms from 'ms'; | 4 | import ms from 'ms'; |
5 | import { ensureFileSync, pathExistsSync, writeFileSync } from 'fs-extra'; | 5 | import { ensureFileSync, pathExistsSync, writeFileSync } from 'fs-extra'; |
@@ -67,6 +67,8 @@ export default class ServicesStore extends TypedStore { | |||
67 | constructor(stores: Stores, api: ApiInterface, actions: Actions) { | 67 | constructor(stores: Stores, api: ApiInterface, actions: Actions) { |
68 | super(stores, api, actions); | 68 | super(stores, api, actions); |
69 | 69 | ||
70 | makeObservable(this); | ||
71 | |||
70 | // Register action handlers | 72 | // Register action handlers |
71 | this.actions.service.setActive.listen(this._setActive.bind(this)); | 73 | this.actions.service.setActive.listen(this._setActive.bind(this)); |
72 | this.actions.service.blurActive.listen(this._blurActive.bind(this)); | 74 | this.actions.service.blurActive.listen(this._blurActive.bind(this)); |
diff --git a/src/stores/SettingsStore.ts b/src/stores/SettingsStore.ts index 0296ba0e7..a03d3c188 100644 --- a/src/stores/SettingsStore.ts +++ b/src/stores/SettingsStore.ts | |||
@@ -1,6 +1,7 @@ | |||
1 | |||
1 | import { ipcRenderer } from 'electron'; | 2 | import { ipcRenderer } from 'electron'; |
2 | import { getCurrentWindow } from '@electron/remote'; | 3 | import { getCurrentWindow } from '@electron/remote'; |
3 | import { action, computed, observable, reaction } from 'mobx'; | 4 | import { action, computed, makeObservable, observable, reaction } from 'mobx'; |
4 | import localStorage from 'mobx-localstorage'; | 5 | import localStorage from 'mobx-localstorage'; |
5 | import { Stores } from '../@types/stores.types'; | 6 | import { Stores } from '../@types/stores.types'; |
6 | import { ApiInterface } from '../api'; | 7 | import { ApiInterface } from '../api'; |
@@ -22,7 +23,7 @@ export default class SettingsStore extends TypedStore { | |||
22 | 'updateAppSettings', | 23 | 'updateAppSettings', |
23 | ); | 24 | ); |
24 | 25 | ||
25 | loaded = false; | 26 | @observable loaded: boolean = false; |
26 | 27 | ||
27 | fileSystemSettingsTypes = FILE_SYSTEM_SETTINGS_TYPES; | 28 | fileSystemSettingsTypes = FILE_SYSTEM_SETTINGS_TYPES; |
28 | 29 | ||
@@ -34,6 +35,8 @@ export default class SettingsStore extends TypedStore { | |||
34 | constructor(stores: Stores, api: ApiInterface, actions: Actions) { | 35 | constructor(stores: Stores, api: ApiInterface, actions: Actions) { |
35 | super(stores, api, actions); | 36 | super(stores, api, actions); |
36 | 37 | ||
38 | makeObservable(this); | ||
39 | |||
37 | // Register action handlers | 40 | // Register action handlers |
38 | this.actions.settings.update.listen(this._update.bind(this)); | 41 | this.actions.settings.update.listen(this._update.bind(this)); |
39 | this.actions.settings.remove.listen(this._remove.bind(this)); | 42 | this.actions.settings.remove.listen(this._remove.bind(this)); |
diff --git a/src/stores/UIStore.ts b/src/stores/UIStore.ts index c43c6d8c7..e0589729f 100644 --- a/src/stores/UIStore.ts +++ b/src/stores/UIStore.ts | |||
@@ -1,4 +1,4 @@ | |||
1 | import { action, observable, computed, reaction } from 'mobx'; | 1 | import { action, observable, computed, reaction, makeObservable } from 'mobx'; |
2 | import { nativeTheme } from '@electron/remote'; | 2 | import { nativeTheme } from '@electron/remote'; |
3 | 3 | ||
4 | import { Stores } from '../@types/stores.types'; | 4 | import { Stores } from '../@types/stores.types'; |
@@ -14,6 +14,9 @@ export default class UIStore extends TypedStore { | |||
14 | 14 | ||
15 | constructor(stores: Stores, api: ApiInterface, actions: Actions) { | 15 | constructor(stores: Stores, api: ApiInterface, actions: Actions) { |
16 | super(stores, api, actions); | 16 | super(stores, api, actions); |
17 | |||
18 | makeObservable(this); | ||
19 | |||
17 | // Register action handlers | 20 | // Register action handlers |
18 | this.actions.ui.openSettings.listen(this._openSettings.bind(this)); | 21 | this.actions.ui.openSettings.listen(this._openSettings.bind(this)); |
19 | this.actions.ui.closeSettings.listen(this._closeSettings.bind(this)); | 22 | this.actions.ui.closeSettings.listen(this._closeSettings.bind(this)); |
diff --git a/src/stores/UserStore.ts b/src/stores/UserStore.ts index b9c3c7576..c5e67c966 100644 --- a/src/stores/UserStore.ts +++ b/src/stores/UserStore.ts | |||
@@ -1,4 +1,4 @@ | |||
1 | import { observable, computed, action } from 'mobx'; | 1 | import { observable, computed, action, makeObservable } from 'mobx'; |
2 | import moment from 'moment'; | 2 | import moment from 'moment'; |
3 | import jwt from 'jsonwebtoken'; | 3 | import jwt from 'jsonwebtoken'; |
4 | import localStorage from 'mobx-localstorage'; | 4 | import localStorage from 'mobx-localstorage'; |
@@ -93,6 +93,8 @@ export default class UserStore extends TypedStore { | |||
93 | constructor(stores: Stores, api: ApiInterface, actions: Actions) { | 93 | constructor(stores: Stores, api: ApiInterface, actions: Actions) { |
94 | super(stores, api, actions); | 94 | super(stores, api, actions); |
95 | 95 | ||
96 | makeObservable(this); | ||
97 | |||
96 | // Register action handlers | 98 | // Register action handlers |
97 | this.actions.user.login.listen(this._login.bind(this)); | 99 | this.actions.user.login.listen(this._login.bind(this)); |
98 | this.actions.user.retrievePassword.listen( | 100 | this.actions.user.retrievePassword.listen( |
diff --git a/src/stores/index.ts b/src/stores/index.ts index d31f2c933..8836f2892 100644 --- a/src/stores/index.ts +++ b/src/stores/index.ts | |||
@@ -1,4 +1,4 @@ | |||
1 | import { RouterStore } from 'mobx-react-router'; | 1 | import { RouterStore } from '@superwf/mobx-react-router'; |
2 | import { ApiInterface } from '../api'; | 2 | import { ApiInterface } from '../api'; |
3 | import { Actions } from '../actions/lib/actions'; | 3 | import { Actions } from '../actions/lib/actions'; |
4 | import AppStore from './AppStore'; | 4 | import AppStore from './AppStore'; |
diff --git a/src/stores/lib/Request.js b/src/stores/lib/Request.js index 0ac36a218..e58341790 100644 --- a/src/stores/lib/Request.js +++ b/src/stores/lib/Request.js | |||
@@ -1,4 +1,4 @@ | |||
1 | import { observable, action, computed } from 'mobx'; | 1 | import { observable, action, computed, makeObservable } from 'mobx'; |
2 | import { isEqual } from 'lodash/fp'; | 2 | import { isEqual } from 'lodash/fp'; |
3 | 3 | ||
4 | export default class Request { | 4 | export default class Request { |
@@ -29,6 +29,8 @@ export default class Request { | |||
29 | _currentApiCall = null; | 29 | _currentApiCall = null; |
30 | 30 | ||
31 | constructor(api, method) { | 31 | constructor(api, method) { |
32 | makeObservable(this); | ||
33 | |||
32 | this._api = api; | 34 | this._api = api; |
33 | this._method = method; | 35 | this._method = method; |
34 | } | 36 | } |
diff --git a/src/stores/lib/TypedStore.ts b/src/stores/lib/TypedStore.ts index c97ae1aa5..e44eadd32 100644 --- a/src/stores/lib/TypedStore.ts +++ b/src/stores/lib/TypedStore.ts | |||
@@ -1,4 +1,4 @@ | |||
1 | import { computed, IReactionPublic, observable } from 'mobx'; | 1 | import { computed, IReactionPublic, makeObservable, observable } from 'mobx'; |
2 | import { Actions } from '../../actions/lib/actions'; | 2 | import { Actions } from '../../actions/lib/actions'; |
3 | import { ApiInterface } from '../../api'; | 3 | import { ApiInterface } from '../../api'; |
4 | import { Stores } from '../../@types/stores.types'; | 4 | import { Stores } from '../../@types/stores.types'; |
@@ -9,6 +9,12 @@ export default abstract class TypedStore { | |||
9 | 9 | ||
10 | @observable _status: any = null; | 10 | @observable _status: any = null; |
11 | 11 | ||
12 | stores: Stores; | ||
13 | |||
14 | api: ApiInterface; | ||
15 | |||
16 | actions: Actions; | ||
17 | |||
12 | @computed get actionStatus() { | 18 | @computed get actionStatus() { |
13 | return this._status || []; | 19 | return this._status || []; |
14 | } | 20 | } |
@@ -17,11 +23,13 @@ export default abstract class TypedStore { | |||
17 | this._status = status; | 23 | this._status = status; |
18 | } | 24 | } |
19 | 25 | ||
20 | constructor( | 26 | constructor(stores: Stores, api: ApiInterface, actions: Actions) { |
21 | public readonly stores: Stores, | 27 | makeObservable(this); |
22 | public readonly api: ApiInterface, | 28 | |
23 | public readonly actions: Actions, | 29 | this.stores = stores; |
24 | ) {} | 30 | this.api = api; |
31 | this.actions = actions; | ||
32 | } | ||
25 | 33 | ||
26 | registerReactions(reactions: { (r: IReactionPublic): void }[]): void { | 34 | registerReactions(reactions: { (r: IReactionPublic): void }[]): void { |
27 | for (const reaction of reactions) { | 35 | for (const reaction of reactions) { |