diff options
author | Markus Hatvan <markus_hatvan@aon.at> | 2021-10-15 09:48:06 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-15 09:48:06 +0200 |
commit | 14d2364fc69e0222133115c55a36286986006098 (patch) | |
tree | 9e9b3c41ef742bbe87ca1632b292c67043051957 /src/stores/lib | |
parent | 5.6.3-nightly.34 [skip ci] (diff) | |
download | ferdium-app-14d2364fc69e0222133115c55a36286986006098.tar.gz ferdium-app-14d2364fc69e0222133115c55a36286986006098.tar.zst ferdium-app-14d2364fc69e0222133115c55a36286986006098.zip |
chore: update eslint setup (#2074)
Diffstat (limited to 'src/stores/lib')
-rw-r--r-- | src/stores/lib/Request.js | 82 | ||||
-rw-r--r-- | src/stores/lib/Store.js | 3 |
2 files changed, 55 insertions, 30 deletions
diff --git a/src/stores/lib/Request.js b/src/stores/lib/Request.js index 39f32729a..65871ea17 100644 --- a/src/stores/lib/Request.js +++ b/src/stores/lib/Request.js | |||
@@ -38,42 +38,56 @@ export default class Request { | |||
38 | if (this._isWaitingForResponse) return this; | 38 | if (this._isWaitingForResponse) return this; |
39 | 39 | ||
40 | if (!this._api[this._method]) { | 40 | if (!this._api[this._method]) { |
41 | throw new Error(`Missing method <${this._method}> on api object:`, this._api); | 41 | throw new Error( |
42 | `Missing method <${this._method}> on api object:`, | ||
43 | this._api, | ||
44 | ); | ||
42 | } | 45 | } |
43 | 46 | ||
44 | // This timeout is necessary to avoid warnings from mobx | 47 | // This timeout is necessary to avoid warnings from mobx |
45 | // regarding triggering actions as side-effect of getters | 48 | // regarding triggering actions as side-effect of getters |
46 | setTimeout(action(() => { | 49 | setTimeout( |
47 | this.isExecuting = true; | 50 | action(() => { |
48 | }), 0); | 51 | this.isExecuting = true; |
52 | }), | ||
53 | 0, | ||
54 | ); | ||
49 | 55 | ||
50 | // Issue api call & save it as promise that is handled to update the results of the operation | 56 | // Issue api call & save it as promise that is handled to update the results of the operation |
51 | this._promise = new Promise((resolve, reject) => { | 57 | this._promise = new Promise((resolve, reject) => { |
52 | this._api[this._method](...callArgs) | 58 | this._api[this._method](...callArgs) |
53 | .then((result) => { | 59 | .then(result => { |
54 | setTimeout(action(() => { | 60 | setTimeout( |
55 | this.result = result; | 61 | action(() => { |
56 | if (this._currentApiCall) this._currentApiCall.result = result; | 62 | this.result = result; |
57 | this.isExecuting = false; | 63 | if (this._currentApiCall) this._currentApiCall.result = result; |
58 | this.isError = false; | 64 | this.isExecuting = false; |
59 | this.wasExecuted = true; | 65 | this.isError = false; |
60 | this._isWaitingForResponse = false; | 66 | this.wasExecuted = true; |
61 | this._triggerHooks(); | 67 | this._isWaitingForResponse = false; |
62 | resolve(result); | 68 | this._triggerHooks(); |
63 | }), 1); | 69 | resolve(result); |
70 | }), | ||
71 | 1, | ||
72 | ); | ||
64 | return result; | 73 | return result; |
65 | }) | 74 | }) |
66 | .catch(action((error) => { | 75 | .catch( |
67 | setTimeout(action(() => { | 76 | action(error => { |
68 | this.error = error; | 77 | setTimeout( |
69 | this.isExecuting = false; | 78 | action(() => { |
70 | this.isError = true; | 79 | this.error = error; |
71 | this.wasExecuted = true; | 80 | this.isExecuting = false; |
72 | this._isWaitingForResponse = false; | 81 | this.isError = true; |
73 | this._triggerHooks(); | 82 | this.wasExecuted = true; |
74 | reject(error); | 83 | this._isWaitingForResponse = false; |
75 | }), 1); | 84 | this._triggerHooks(); |
76 | })); | 85 | reject(error); |
86 | }), | ||
87 | 1, | ||
88 | ); | ||
89 | }), | ||
90 | ); | ||
77 | }); | 91 | }); |
78 | 92 | ||
79 | this._isWaitingForResponse = true; | 93 | this._isWaitingForResponse = true; |
@@ -89,7 +103,11 @@ export default class Request { | |||
89 | retry = () => this.reload(); | 103 | retry = () => this.reload(); |
90 | 104 | ||
91 | isExecutingWithArgs(...args) { | 105 | isExecutingWithArgs(...args) { |
92 | return this.isExecuting && this._currentApiCall && isEqual(this._currentApiCall.args, args); | 106 | return ( |
107 | this.isExecuting && | ||
108 | this._currentApiCall && | ||
109 | isEqual(this._currentApiCall.args, args) | ||
110 | ); | ||
93 | } | 111 | } |
94 | 112 | ||
95 | @computed get isExecutingFirstTime() { | 113 | @computed get isExecutingFirstTime() { |
@@ -97,12 +115,18 @@ export default class Request { | |||
97 | } | 115 | } |
98 | 116 | ||
99 | then(...args) { | 117 | then(...args) { |
100 | if (!this._promise) throw new Error('You have to call Request::execute before you can access it as promise'); | 118 | if (!this._promise) |
119 | throw new Error( | ||
120 | 'You have to call Request::execute before you can access it as promise', | ||
121 | ); | ||
101 | return this._promise.then(...args); | 122 | return this._promise.then(...args); |
102 | } | 123 | } |
103 | 124 | ||
104 | catch(...args) { | 125 | catch(...args) { |
105 | if (!this._promise) throw new Error('You have to call Request::execute before you can access it as promise'); | 126 | if (!this._promise) |
127 | throw new Error( | ||
128 | 'You have to call Request::execute before you can access it as promise', | ||
129 | ); | ||
106 | return this._promise.catch(...args); | 130 | return this._promise.catch(...args); |
107 | } | 131 | } |
108 | 132 | ||
diff --git a/src/stores/lib/Store.js b/src/stores/lib/Store.js index b39070ce8..a867c3a46 100644 --- a/src/stores/lib/Store.js +++ b/src/stores/lib/Store.js | |||
@@ -28,7 +28,8 @@ export default class Store { | |||
28 | } | 28 | } |
29 | 29 | ||
30 | registerReactions(reactions) { | 30 | registerReactions(reactions) { |
31 | for (const reaction of reactions) this._reactions.push(new Reaction(reaction)); | 31 | for (const reaction of reactions) |
32 | this._reactions.push(new Reaction(reaction)); | ||
32 | } | 33 | } |
33 | 34 | ||
34 | setup() {} | 35 | setup() {} |