diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/app.jsx (renamed from src/app.js) | 2 | ||||
-rw-r--r-- | src/stores.types.ts | 113 | ||||
-rw-r--r-- | src/stores/FeaturesStore.ts (renamed from src/stores/FeaturesStore.js) | 15 | ||||
-rw-r--r-- | src/stores/GlobalErrorStore.ts (renamed from src/stores/GlobalErrorStore.js) | 67 | ||||
-rw-r--r-- | src/stores/lib/TypedStore.ts | 6 |
5 files changed, 90 insertions, 113 deletions
diff --git a/src/app.js b/src/app.jsx index c92d044e6..db0dee392 100644 --- a/src/app.js +++ b/src/app.jsx | |||
@@ -38,7 +38,7 @@ window.addEventListener('load', () => { | |||
38 | render() { | 38 | render() { |
39 | const preparedApp = ( | 39 | const preparedApp = ( |
40 | <Provider stores={stores} actions={actions}> | 40 | <Provider stores={stores} actions={actions}> |
41 | <I18N> | 41 | <I18N stores={{ app: stores.app, user: stores.user }}> |
42 | <Routes history={history} /> | 42 | <Routes history={history} /> |
43 | </I18N> | 43 | </I18N> |
44 | </Provider> | 44 | </Provider> |
diff --git a/src/stores.types.ts b/src/stores.types.ts index b0912c463..462d862d9 100644 --- a/src/stores.types.ts +++ b/src/stores.types.ts | |||
@@ -3,6 +3,7 @@ import Recipe from './models/Recipe'; | |||
3 | import Service from './models/Service'; | 3 | import Service from './models/Service'; |
4 | import User from './models/User'; | 4 | import User from './models/User'; |
5 | import { CachedRequest } from './stores/lib/CachedRequest'; | 5 | import { CachedRequest } from './stores/lib/CachedRequest'; |
6 | import Reaction from './stores/lib/Reaction'; | ||
6 | 7 | ||
7 | export interface FerdiumStores { | 8 | export interface FerdiumStores { |
8 | app: AppStore; | 9 | app: AppStore; |
@@ -61,11 +62,21 @@ interface Api { | |||
61 | user: UserStore; | 62 | user: UserStore; |
62 | } | 63 | } |
63 | 64 | ||
64 | interface AppStore { | 65 | interface TypedStore { |
65 | actions: Actions; | 66 | actions: Actions; |
67 | api: Api; | ||
68 | stores: Stores; | ||
69 | _reactions: Reaction[]; | ||
70 | _status: any; | ||
71 | actionStatus: () => void; | ||
72 | initialize: () => void; | ||
73 | tearDown: () => void; | ||
74 | resetStatus: () => void; | ||
75 | } | ||
76 | |||
77 | interface AppStore extends TypedStore { | ||
66 | accentColor: string; | 78 | accentColor: string; |
67 | progressbarAccentColor: string; | 79 | progressbarAccentColor: string; |
68 | api: Api; | ||
69 | authRequestFailed: () => void; | 80 | authRequestFailed: () => void; |
70 | autoLaunchOnStart: () => void; | 81 | autoLaunchOnStart: () => void; |
71 | automaticUpdates: boolean; | 82 | automaticUpdates: boolean; |
@@ -84,7 +95,6 @@ interface AppStore { | |||
84 | locale: () => void; | 95 | locale: () => void; |
85 | reloadAfterResume: boolean; | 96 | reloadAfterResume: boolean; |
86 | reloadAfterResumeTime: number; | 97 | reloadAfterResumeTime: number; |
87 | stores: Stores; | ||
88 | timeOfflineStart: () => void; | 98 | timeOfflineStart: () => void; |
89 | timeSuspensionStart: () => void; | 99 | timeSuspensionStart: () => void; |
90 | updateStatus: () => void; | 100 | updateStatus: () => void; |
@@ -95,91 +105,56 @@ interface AppStore { | |||
95 | DOWNLOADED: 'DOWNLOADED'; | 105 | DOWNLOADED: 'DOWNLOADED'; |
96 | FAILED: 'FAILED'; | 106 | FAILED: 'FAILED'; |
97 | }; | 107 | }; |
98 | _reactions: any[]; | ||
99 | _status: () => void; | ||
100 | actionStatus: () => void; | ||
101 | cacheSize: () => void; | 108 | cacheSize: () => void; |
102 | debugInfo: () => void; | 109 | debugInfo: () => void; |
103 | } | 110 | } |
104 | 111 | ||
105 | interface CommunityRecipesStore { | 112 | interface CommunityRecipesStore extends TypedStore { |
106 | actions: Actions; | ||
107 | stores: Stores; | ||
108 | _actions: any[]; | ||
109 | _reactions: any[]; | ||
110 | communityRecipes: () => void; | 113 | communityRecipes: () => void; |
111 | } | 114 | } |
112 | 115 | ||
113 | interface FeaturesStore { | 116 | interface FeaturesStore extends TypedStore { |
114 | actions: Actions; | 117 | anonymousFeatures: () => void; |
115 | api: Api; | ||
116 | defaultFeaturesRequest: () => void; | 118 | defaultFeaturesRequest: () => void; |
117 | features: () => void; | 119 | features: () => void; |
118 | featuresRequest: CachedRequest; | 120 | featuresRequest: CachedRequest; |
119 | stores: Stores; | 121 | _monitorLoginStatus: () => void; |
120 | _reactions: any[]; | ||
121 | _status: () => void; | ||
122 | _updateFeatures: () => void; | 122 | _updateFeatures: () => void; |
123 | actionStatus: () => void; | 123 | _setupFeatures: () => void; |
124 | anonymousFeatures: () => void; | ||
125 | } | 124 | } |
126 | 125 | ||
127 | interface GlobalErrorStore { | 126 | interface GlobalErrorStore extends TypedStore { |
128 | actions: Actions; | ||
129 | api: Api; | ||
130 | error: () => void; | 127 | error: () => void; |
131 | messages: () => void; | 128 | messages: () => void; |
132 | response: () => void; | 129 | response: () => void; |
133 | stores: Stores; | ||
134 | _handleRequests: () => void; | 130 | _handleRequests: () => void; |
135 | _reactions: []; | ||
136 | _status: () => void; | ||
137 | actionStatus: () => void; | ||
138 | } | 131 | } |
139 | 132 | ||
140 | interface RecipePreviewsStore { | 133 | interface RecipePreviewsStore extends TypedStore { |
141 | actions: Actions; | ||
142 | allRecipePreviewsRequest: () => void; | 134 | allRecipePreviewsRequest: () => void; |
143 | api: Api; | ||
144 | searchRecipePreviewsRequest: () => void; | 135 | searchRecipePreviewsRequest: () => void; |
145 | stores: Stores; | ||
146 | _reactions: []; | ||
147 | _status: () => void; | ||
148 | actionStatus: () => void; | ||
149 | all: Recipe[]; | 136 | all: Recipe[]; |
150 | dev: Recipe[]; | 137 | dev: Recipe[]; |
151 | searchResults: () => void; | 138 | searchResults: () => void; |
152 | } | 139 | } |
153 | 140 | ||
154 | interface RecipeStore { | 141 | interface RecipeStore extends TypedStore { |
155 | actions: Actions; | ||
156 | allRecipesRequest: () => void; | 142 | allRecipesRequest: () => void; |
157 | api: Api; | ||
158 | getRecipeUpdatesRequest: () => void; | 143 | getRecipeUpdatesRequest: () => void; |
159 | installRecipeRequest: () => void; | 144 | installRecipeRequest: () => void; |
160 | stores: Stores; | ||
161 | _reactions: any[]; | ||
162 | _status: () => void; | ||
163 | actionStatus: () => void; | ||
164 | isInstalled: (id: string) => boolean; | 145 | isInstalled: (id: string) => boolean; |
165 | active: () => void; | 146 | active: () => void; |
166 | all: Recipe[]; | 147 | all: Recipe[]; |
167 | recipeIdForServices: () => void; | 148 | recipeIdForServices: () => void; |
168 | } | 149 | } |
169 | 150 | ||
170 | interface RequestsStore { | 151 | interface RequestsStore extends TypedStore { |
171 | actions: Actions; | ||
172 | api: Api; | ||
173 | localServerPort: () => void; | 152 | localServerPort: () => void; |
174 | retries: number; | 153 | retries: number; |
175 | retryDelay: number; | 154 | retryDelay: number; |
176 | servicesRequest: () => void; | 155 | servicesRequest: () => void; |
177 | showRequiredRequestsError: () => void; | 156 | showRequiredRequestsError: () => void; |
178 | stores: Stores; | ||
179 | userInfoRequest: () => void; | 157 | userInfoRequest: () => void; |
180 | _reactions: any[]; | ||
181 | _status: () => void; | ||
182 | actionStatus: () => void; | ||
183 | areRequiredRequestsLoading: () => void; | 158 | areRequiredRequestsLoading: () => void; |
184 | areRequiredRequestsSuccessful: () => void; | 159 | areRequiredRequestsSuccessful: () => void; |
185 | } | 160 | } |
@@ -203,9 +178,7 @@ interface RouterStore { | |||
203 | replace: () => void; | 178 | replace: () => void; |
204 | } | 179 | } |
205 | 180 | ||
206 | export interface ServicesStore { | 181 | export interface ServicesStore extends TypedStore { |
207 | actions: Actions; | ||
208 | api: Api; | ||
209 | clearCacheRequest: () => void; | 182 | clearCacheRequest: () => void; |
210 | createServiceRequest: () => void; | 183 | createServiceRequest: () => void; |
211 | deleteServiceRequest: () => void; | 184 | deleteServiceRequest: () => void; |
@@ -214,11 +187,7 @@ export interface ServicesStore { | |||
214 | lastUsedServices: () => void; | 187 | lastUsedServices: () => void; |
215 | reorderServicesRequest: () => void; | 188 | reorderServicesRequest: () => void; |
216 | serviceMaintenanceTick: () => void; | 189 | serviceMaintenanceTick: () => void; |
217 | stores: Stores; | ||
218 | updateServiceRequest: () => void; | 190 | updateServiceRequest: () => void; |
219 | _reactions: any[]; | ||
220 | _status: () => void; | ||
221 | actionStatus: () => void; | ||
222 | active: () => void; | 191 | active: () => void; |
223 | activeSettings: () => void; | 192 | activeSettings: () => void; |
224 | all: Service[]; | 193 | all: Service[]; |
@@ -235,17 +204,11 @@ interface ISettings { | |||
235 | [key: string]: any; | 204 | [key: string]: any; |
236 | } | 205 | } |
237 | 206 | ||
238 | interface SettingsStore { | 207 | interface SettingsStore extends TypedStore { |
239 | actions: Actions; | ||
240 | api: Api; | ||
241 | fileSystemSettingsTypes: any[]; | 208 | fileSystemSettingsTypes: any[]; |
242 | loaded: boolean; | 209 | loaded: boolean; |
243 | stores: Stores; | ||
244 | updateAppSettingsRequest: () => void; | 210 | updateAppSettingsRequest: () => void; |
245 | _fileSystemSettingsCache: () => void; | 211 | _fileSystemSettingsCache: () => void; |
246 | _reactions: []; | ||
247 | _status: () => void; | ||
248 | actionStatus: () => void; | ||
249 | all: ISettings; | 212 | all: ISettings; |
250 | app: AppStore; | 213 | app: AppStore; |
251 | migration: () => void; | 214 | migration: () => void; |
@@ -254,22 +217,17 @@ interface SettingsStore { | |||
254 | stats: () => void; | 217 | stats: () => void; |
255 | } | 218 | } |
256 | 219 | ||
257 | interface TodosStore { | 220 | interface TodosStore extends TypedStore { |
258 | actions: Actions; | ||
259 | api: Api; | ||
260 | isFeatureActive: () => void; | 221 | isFeatureActive: () => void; |
261 | isInitialized: true; | 222 | isInitialized: true; |
262 | stores: Stores; | ||
263 | userAgentModel: () => void; | 223 | userAgentModel: () => void; |
264 | webview: () => void; | 224 | webview: () => void; |
265 | _actions: any[]; | ||
266 | _allReactions: any[]; | 225 | _allReactions: any[]; |
267 | _firstLaunchReaction: () => void; | 226 | _firstLaunchReaction: () => void; |
268 | _goToService: () => void; | 227 | _goToService: () => void; |
269 | _handleNewWindowEvent: () => void; | 228 | _handleNewWindowEvent: () => void; |
270 | _onTodosClientInitialized: () => void; | 229 | _onTodosClientInitialized: () => void; |
271 | _openDevTools: () => void; | 230 | _openDevTools: () => void; |
272 | _reactions: any[]; | ||
273 | _reload: () => void; | 231 | _reload: () => void; |
274 | _routeCheckReaction: () => void; | 232 | _routeCheckReaction: () => void; |
275 | _updateSettings: () => void; | 233 | _updateSettings: () => void; |
@@ -292,14 +250,8 @@ interface TodosStore { | |||
292 | _toggleTodosPanel: () => void; | 250 | _toggleTodosPanel: () => void; |
293 | } | 251 | } |
294 | 252 | ||
295 | interface UIStore { | 253 | interface UIStore extends TypedStore { |
296 | actions: Actions; | ||
297 | api: Api; | ||
298 | isOsDarkThemeActive: () => void; | 254 | isOsDarkThemeActive: () => void; |
299 | stores: Stores; | ||
300 | _reactions: []; | ||
301 | _status: () => void; | ||
302 | actionStatus: () => void; | ||
303 | showServicesUpdatedInfoBar: boolean; | 255 | showServicesUpdatedInfoBar: boolean; |
304 | isDarkThemeActive: () => void; | 256 | isDarkThemeActive: () => void; |
305 | isSplitModeActive: () => void; | 257 | isSplitModeActive: () => void; |
@@ -308,7 +260,7 @@ interface UIStore { | |||
308 | theme: () => void; | 260 | theme: () => void; |
309 | } | 261 | } |
310 | 262 | ||
311 | interface UserStore { | 263 | interface UserStore extends TypedStore { |
312 | BASE_ROUTE: '/auth'; | 264 | BASE_ROUTE: '/auth'; |
313 | CHANGE_SERVER_ROUTE: '/auth/server'; | 265 | CHANGE_SERVER_ROUTE: '/auth/server'; |
314 | IMPORT_ROUTE: '/auth/signup/import'; | 266 | IMPORT_ROUTE: '/auth/signup/import'; |
@@ -320,9 +272,6 @@ interface UserStore { | |||
320 | SIGNUP_ROUTE: '/auth/signup'; | 272 | SIGNUP_ROUTE: '/auth/signup'; |
321 | WELCOME_ROUTE: '/auth/welcome'; | 273 | WELCOME_ROUTE: '/auth/welcome'; |
322 | accountType: () => void; | 274 | accountType: () => void; |
323 | actionStatus: () => void; | ||
324 | actions: Actions; | ||
325 | api: Api; | ||
326 | authToken: () => void; | 275 | authToken: () => void; |
327 | deleteAccountRequest: () => void; | 276 | deleteAccountRequest: () => void; |
328 | fetchUserInfoInterval: null; | 277 | fetchUserInfoInterval: null; |
@@ -339,12 +288,9 @@ interface UserStore { | |||
339 | logoutReasonTypes: { SERVER: 'SERVER' }; | 288 | logoutReasonTypes: { SERVER: 'SERVER' }; |
340 | passwordRequest: () => void; | 289 | passwordRequest: () => void; |
341 | signupRequest: () => void; | 290 | signupRequest: () => void; |
342 | stores: Stores; | ||
343 | updateUserInfoRequest: () => void; | 291 | updateUserInfoRequest: () => void; |
344 | userData: () => void; | 292 | userData: () => void; |
345 | _reactions: any[]; | ||
346 | _requireAuthenticatedUser: () => void; | 293 | _requireAuthenticatedUser: () => void; |
347 | _status: () => void; | ||
348 | changeServerRoute: () => void; | 294 | changeServerRoute: () => void; |
349 | data: User; | 295 | data: User; |
350 | importRoute: () => void; | 296 | importRoute: () => void; |
@@ -360,7 +306,7 @@ interface UserStore { | |||
360 | team: () => void; | 306 | team: () => void; |
361 | } | 307 | } |
362 | 308 | ||
363 | export interface WorkspacesStore { | 309 | export interface WorkspacesStore extends TypedStore { |
364 | activeWorkspace: () => void; | 310 | activeWorkspace: () => void; |
365 | delete: ({ workspace }) => void; | 311 | delete: ({ workspace }) => void; |
366 | update: ({ workspace }) => void; | 312 | update: ({ workspace }) => void; |
@@ -373,17 +319,14 @@ export interface WorkspacesStore { | |||
373 | isSwitchingWorkspace: () => void; | 319 | isSwitchingWorkspace: () => void; |
374 | isWorkspaceDrawerOpen: () => void; | 320 | isWorkspaceDrawerOpen: () => void; |
375 | nextWorkspace: () => void; | 321 | nextWorkspace: () => void; |
376 | stores: Stores; | ||
377 | workspaces: Workspace[]; | 322 | workspaces: Workspace[]; |
378 | workspaceBeingEdited: () => void; | 323 | workspaceBeingEdited: () => void; |
379 | _actions: any[]; | ||
380 | _activateLastUsedWorkspaceReaction: () => void; | 324 | _activateLastUsedWorkspaceReaction: () => void; |
381 | _allActions: any[]; | 325 | _allActions: any[]; |
382 | _allReactions: any[]; | 326 | _allReactions: any[]; |
383 | _cleanupInvalidServiceReferences: () => void; | 327 | _cleanupInvalidServiceReferences: () => void; |
384 | _getWorkspaceById: () => void; | 328 | _getWorkspaceById: () => void; |
385 | _openDrawerWithSettingsReaction: () => void; | 329 | _openDrawerWithSettingsReaction: () => void; |
386 | _reactions: any[]; | ||
387 | _setActiveServiceOnWorkspaceSwitchReaction: () => void; | 330 | _setActiveServiceOnWorkspaceSwitchReaction: () => void; |
388 | _setWorkspaceBeingEditedReaction: () => void; | 331 | _setWorkspaceBeingEditedReaction: () => void; |
389 | _toggleKeepAllWorkspacesLoadedSetting: () => void; | 332 | _toggleKeepAllWorkspacesLoadedSetting: () => void; |
diff --git a/src/stores/FeaturesStore.js b/src/stores/FeaturesStore.ts index e2c0c08ef..b63c252df 100644 --- a/src/stores/FeaturesStore.js +++ b/src/stores/FeaturesStore.ts | |||
@@ -1,8 +1,6 @@ | |||
1 | import { computed, observable, runInAction } from 'mobx'; | 1 | import { computed, observable, runInAction } from 'mobx'; |
2 | 2 | ||
3 | import Store from './lib/Store'; | ||
4 | import CachedRequest from './lib/CachedRequest'; | 3 | import CachedRequest from './lib/CachedRequest'; |
5 | |||
6 | import serviceProxy from '../features/serviceProxy'; | 4 | import serviceProxy from '../features/serviceProxy'; |
7 | import basicAuth from '../features/basicAuth'; | 5 | import basicAuth from '../features/basicAuth'; |
8 | import workspaces from '../features/workspaces'; | 6 | import workspaces from '../features/workspaces'; |
@@ -11,8 +9,9 @@ import publishDebugInfo from '../features/publishDebugInfo'; | |||
11 | import communityRecipes from '../features/communityRecipes'; | 9 | import communityRecipes from '../features/communityRecipes'; |
12 | import todos from '../features/todos'; | 10 | import todos from '../features/todos'; |
13 | import appearance from '../features/appearance'; | 11 | import appearance from '../features/appearance'; |
12 | import TypedStore from './lib/TypedStore'; | ||
14 | 13 | ||
15 | export default class FeaturesStore extends Store { | 14 | export default class FeaturesStore extends TypedStore { |
16 | @observable defaultFeaturesRequest = new CachedRequest( | 15 | @observable defaultFeaturesRequest = new CachedRequest( |
17 | this.api.features, | 16 | this.api.features, |
18 | 'default', | 17 | 'default', |
@@ -25,7 +24,7 @@ export default class FeaturesStore extends Store { | |||
25 | 24 | ||
26 | @observable features = {}; | 25 | @observable features = {}; |
27 | 26 | ||
28 | async setup() { | 27 | async setup(): Promise<void> { |
29 | this.registerReactions([ | 28 | this.registerReactions([ |
30 | this._updateFeatures, | 29 | this._updateFeatures, |
31 | this._monitorLoginStatus.bind(this), | 30 | this._monitorLoginStatus.bind(this), |
@@ -35,11 +34,11 @@ export default class FeaturesStore extends Store { | |||
35 | setTimeout(this._setupFeatures.bind(this), 1); | 34 | setTimeout(this._setupFeatures.bind(this), 1); |
36 | } | 35 | } |
37 | 36 | ||
38 | @computed get anonymousFeatures() { | 37 | @computed get anonymousFeatures(): any { |
39 | return this.defaultFeaturesRequest.execute().result || {}; | 38 | return this.defaultFeaturesRequest.execute().result || {}; |
40 | } | 39 | } |
41 | 40 | ||
42 | _updateFeatures = () => { | 41 | _updateFeatures = (): void => { |
43 | const features = {}; | 42 | const features = {}; |
44 | if (this.stores.user.isLoggedIn) { | 43 | if (this.stores.user.isLoggedIn) { |
45 | let requestResult = {}; | 44 | let requestResult = {}; |
@@ -55,7 +54,7 @@ export default class FeaturesStore extends Store { | |||
55 | }); | 54 | }); |
56 | }; | 55 | }; |
57 | 56 | ||
58 | _monitorLoginStatus() { | 57 | _monitorLoginStatus(): void { |
59 | if (this.stores.user.isLoggedIn) { | 58 | if (this.stores.user.isLoggedIn) { |
60 | this.featuresRequest.invalidate({ immediately: true }); | 59 | this.featuresRequest.invalidate({ immediately: true }); |
61 | } else { | 60 | } else { |
@@ -64,7 +63,7 @@ export default class FeaturesStore extends Store { | |||
64 | } | 63 | } |
65 | } | 64 | } |
66 | 65 | ||
67 | _setupFeatures() { | 66 | _setupFeatures(): void { |
68 | serviceProxy(this.stores); | 67 | serviceProxy(this.stores); |
69 | basicAuth(); | 68 | basicAuth(); |
70 | workspaces(this.stores, this.actions); | 69 | workspaces(this.stores, this.actions); |
diff --git a/src/stores/GlobalErrorStore.js b/src/stores/GlobalErrorStore.ts index 356a6f298..cb364574b 100644 --- a/src/stores/GlobalErrorStore.js +++ b/src/stores/GlobalErrorStore.ts | |||
@@ -1,35 +1,61 @@ | |||
1 | import { observable, action } from 'mobx'; | 1 | import { observable, action } from 'mobx'; |
2 | import Store from './lib/Store'; | 2 | import { Actions } from 'src/actions/lib/actions'; |
3 | import { ApiInterface } from 'src/api'; | ||
4 | import { Stores } from 'src/stores.types'; | ||
3 | import Request from './lib/Request'; | 5 | import Request from './lib/Request'; |
6 | import TypedStore from './lib/TypedStore'; | ||
4 | 7 | ||
5 | export default class GlobalErrorStore extends Store { | 8 | interface Message { |
6 | @observable error = null; | 9 | type: 'error' | 'log' | 'info'; |
10 | error?: { | ||
11 | message?: string; | ||
12 | status?: number; | ||
13 | }; | ||
14 | request?: { | ||
15 | result: any; | ||
16 | wasExecuted: any; | ||
17 | method: any; | ||
18 | }; | ||
19 | response?: any; | ||
20 | server?: any; | ||
21 | info?: any; | ||
22 | url?: string; | ||
23 | line?: number; | ||
24 | } | ||
25 | |||
26 | export default class GlobalErrorStore extends TypedStore { | ||
27 | @observable error: any | null = null; | ||
7 | 28 | ||
8 | @observable messages = []; | 29 | @observable messages: Message[] = []; |
9 | 30 | ||
10 | @observable response = {}; | 31 | @observable response: object = {}; |
11 | 32 | ||
12 | constructor(...args) { | 33 | // TODO: Get rid of the @ts-ignores in this function. |
13 | super(...args); | 34 | constructor(stores: Stores, api: ApiInterface, actions: Actions) { |
35 | super(stores, api, actions); | ||
14 | 36 | ||
15 | window.addEventListener('error', (...errorArgs) => { | 37 | window.addEventListener('error', (...errorArgs: any[]): void => { |
38 | // @ts-ignore ts-message: Expected 5 arguments, but got 2. | ||
16 | this._handleConsoleError.call(this, ['error', ...errorArgs]); | 39 | this._handleConsoleError.call(this, ['error', ...errorArgs]); |
17 | }); | 40 | }); |
18 | 41 | ||
19 | const origConsoleError = console.error; | 42 | const origConsoleError = console.error; |
20 | window.console.error = (...errorArgs) => { | 43 | window.console.error = (...errorArgs: any[]) => { |
44 | // @ts-ignore ts-message: Expected 5 arguments, but got 2. | ||
21 | this._handleConsoleError.call(this, ['error', ...errorArgs]); | 45 | this._handleConsoleError.call(this, ['error', ...errorArgs]); |
22 | origConsoleError.apply(this, errorArgs); | 46 | origConsoleError.apply(this, errorArgs); |
23 | }; | 47 | }; |
24 | 48 | ||
25 | const origConsoleLog = console.log; | 49 | const origConsoleLog = console.log; |
26 | window.console.log = (...logArgs) => { | 50 | window.console.log = (...logArgs: any[]) => { |
51 | // @ts-ignore ts-message: Expected 5 arguments, but got 2. | ||
27 | this._handleConsoleError.call(this, ['log', ...logArgs]); | 52 | this._handleConsoleError.call(this, ['log', ...logArgs]); |
28 | origConsoleLog.apply(this, logArgs); | 53 | origConsoleLog.apply(this, logArgs); |
29 | }; | 54 | }; |
30 | 55 | ||
31 | const origConsoleInfo = console.info; | 56 | const origConsoleInfo = console.info; |
32 | window.console.info = (...infoArgs) => { | 57 | window.console.info = (...infoArgs: any[]) => { |
58 | // @ts-ignore ts-message: Expected 5 arguments, but got 2. | ||
33 | this._handleConsoleError.call(this, ['info', ...infoArgs]); | 59 | this._handleConsoleError.call(this, ['info', ...infoArgs]); |
34 | origConsoleInfo.apply(this, infoArgs); | 60 | origConsoleInfo.apply(this, infoArgs); |
35 | }; | 61 | }; |
@@ -37,7 +63,11 @@ export default class GlobalErrorStore extends Store { | |||
37 | Request.registerHook(this._handleRequests); | 63 | Request.registerHook(this._handleRequests); |
38 | } | 64 | } |
39 | 65 | ||
40 | _handleConsoleError(type, error, url, line) { | 66 | async setup(): Promise<void> { |
67 | // Not implemented | ||
68 | } | ||
69 | |||
70 | _handleConsoleError(type: any, error: any, url: string, line: number) { | ||
41 | if (typeof type === 'object' && type.length > 0) { | 71 | if (typeof type === 'object' && type.length > 0) { |
42 | this.messages.push({ | 72 | this.messages.push({ |
43 | type: type[0], | 73 | type: type[0], |
@@ -53,7 +83,13 @@ export default class GlobalErrorStore extends Store { | |||
53 | } | 83 | } |
54 | } | 84 | } |
55 | 85 | ||
56 | _handleRequests = action(async request => { | 86 | @action _handleRequests = async (request: { |
87 | isError: any; | ||
88 | error: { json: () => object | PromiseLike<object> }; | ||
89 | result: any; | ||
90 | wasExecuted: any; | ||
91 | _method: any; | ||
92 | }): Promise<void> => { | ||
57 | if (request.isError) { | 93 | if (request.isError) { |
58 | this.error = request.error; | 94 | this.error = request.error; |
59 | 95 | ||
@@ -63,9 +99,8 @@ export default class GlobalErrorStore extends Store { | |||
63 | } catch { | 99 | } catch { |
64 | this.response = {}; | 100 | this.response = {}; |
65 | } | 101 | } |
66 | if (this.error.status === 401) { | 102 | if (this.error?.status === 401) { |
67 | window['ferdium'].stores.app.authRequestFailed = true; | 103 | window['ferdium'].stores.app.authRequestFailed = true; |
68 | // this.actions.user.logout({ serverLogout: true }); | ||
69 | } | 104 | } |
70 | } | 105 | } |
71 | 106 | ||
@@ -83,5 +118,5 @@ export default class GlobalErrorStore extends Store { | |||
83 | } else { | 118 | } else { |
84 | window['ferdium'].stores.app.authRequestFailed = false; | 119 | window['ferdium'].stores.app.authRequestFailed = false; |
85 | } | 120 | } |
86 | }); | 121 | }; |
87 | } | 122 | } |
diff --git a/src/stores/lib/TypedStore.ts b/src/stores/lib/TypedStore.ts index 5d8bf3bbd..7f9d2d60f 100644 --- a/src/stores/lib/TypedStore.ts +++ b/src/stores/lib/TypedStore.ts | |||
@@ -18,9 +18,9 @@ export default abstract class TypedStore { | |||
18 | } | 18 | } |
19 | 19 | ||
20 | constructor( | 20 | constructor( |
21 | public stores: Stores, | 21 | public readonly stores: Stores, |
22 | public api: ApiInterface, | 22 | public readonly api: ApiInterface, |
23 | public actions: Actions, | 23 | public readonly actions: Actions, |
24 | ) {} | 24 | ) {} |
25 | 25 | ||
26 | registerReactions(reactions: { (r: IReactionPublic): void }[]): void { | 26 | registerReactions(reactions: { (r: IReactionPublic): void }[]): void { |