From 95df3522a15631abc51a4295cae0ea401a8d4e1e Mon Sep 17 00:00:00 2001 From: Markus Hatvan Date: Tue, 14 Sep 2021 19:58:52 +0200 Subject: feat: add eslint-plugin-unicorn (#1936) --- src/stores/lib/CachedRequest.js | 96 +++++++++++++++++++++++------------------ src/stores/lib/Request.js | 2 +- src/stores/lib/Store.js | 6 +-- 3 files changed, 59 insertions(+), 45 deletions(-) (limited to 'src/stores/lib') diff --git a/src/stores/lib/CachedRequest.js b/src/stores/lib/CachedRequest.js index 94f615144..a6dd47f7d 100644 --- a/src/stores/lib/CachedRequest.js +++ b/src/stores/lib/CachedRequest.js @@ -1,4 +1,3 @@ -// @flow import { action } from 'mobx'; import { isEqual, remove } from 'lodash'; import Request from './Request'; @@ -30,48 +29,60 @@ export default class CachedRequest extends Request { // This timeout is necessary to avoid warnings from mobx // regarding triggering actions as side-effect of getters - setTimeout(action(() => { - this.isExecuting = true; - // Apply the previous result from this call immediately (cached) - if (existingApiCall) { - this.result = existingApiCall.result; - } - }), 0); + setTimeout( + action(() => { + this.isExecuting = true; + // Apply the previous result from this call immediately (cached) + if (existingApiCall) { + this.result = existingApiCall.result; + } + }), + 0, + ); // Issue api call & save it as promise that is handled to update the results of the operation - this._promise = new Promise((resolve) => { + this._promise = new Promise(resolve => { this._api[this._method](...callArgs) - .then((result) => { - setTimeout(action(() => { - this.result = result; - if (this._currentApiCall) this._currentApiCall.result = result; - this.isExecuting = false; - this.isError = false; - this.wasExecuted = true; - this._isInvalidated = false; - this._isWaitingForResponse = false; - this._triggerHooks(); - resolve(result); - }), 1); + .then(result => { + setTimeout( + action(() => { + this.result = result; + if (this._currentApiCall) this._currentApiCall.result = result; + this.isExecuting = false; + this.isError = false; + this.wasExecuted = true; + this._isInvalidated = false; + this._isWaitingForResponse = false; + this._triggerHooks(); + resolve(result); + }), + 1, + ); return result; }) - .catch(action((error) => { - setTimeout(action(() => { - this.error = error; - this.isExecuting = false; - this.isError = true; - this.wasExecuted = true; - this._isWaitingForResponse = false; - this._triggerHooks(); - // reject(error); - }), 1); - })); + .catch( + action(error => { + setTimeout( + action(() => { + this.error = error; + this.isExecuting = false; + this.isError = true; + this.wasExecuted = true; + this._isWaitingForResponse = false; + this._triggerHooks(); + // reject(error); + }), + 1, + ); + }), + ); }); this._isWaitingForResponse = true; return this; } + // eslint-disable-next-line unicorn/no-object-as-default-parameter invalidate(options = { immediately: false }) { this._isInvalidated = true; if (options.immediately && this._currentApiCall) { @@ -81,18 +92,21 @@ export default class CachedRequest extends Request { } patch(modify) { - return new Promise((resolve) => { - setTimeout(action(() => { - const override = modify(this.result); - if (override !== undefined) this.result = override; - if (this._currentApiCall) this._currentApiCall.result = this.result; - resolve(this); - }), 0); + return new Promise(resolve => { + setTimeout( + action(() => { + const override = modify(this.result); + if (override !== undefined) this.result = override; + if (this._currentApiCall) this._currentApiCall.result = this.result; + resolve(this); + }), + 0, + ); }); } removeCacheForCallWith(...args) { - remove(this._apiCalls, (c) => isEqual(c.args, args)); + remove(this._apiCalls, c => isEqual(c.args, args)); } _addApiCall(args) { @@ -102,6 +116,6 @@ export default class CachedRequest extends Request { } _findApiCall(args) { - return this._apiCalls.find((c) => isEqual(c.args, args)); + return this._apiCalls.find(c => isEqual(c.args, args)); } } diff --git a/src/stores/lib/Request.js b/src/stores/lib/Request.js index 32ffe4367..39f32729a 100644 --- a/src/stores/lib/Request.js +++ b/src/stores/lib/Request.js @@ -107,7 +107,7 @@ export default class Request { } _triggerHooks() { - Request._hooks.forEach((hook) => hook(this)); + for (const hook of Request._hooks) hook(this); } reset = () => { diff --git a/src/stores/lib/Store.js b/src/stores/lib/Store.js index b03a7e725..b39070ce8 100644 --- a/src/stores/lib/Store.js +++ b/src/stores/lib/Store.js @@ -28,18 +28,18 @@ export default class Store { } registerReactions(reactions) { - reactions.forEach((reaction) => this._reactions.push(new Reaction(reaction))); + for (const reaction of reactions) this._reactions.push(new Reaction(reaction)); } setup() {} initialize() { this.setup(); - this._reactions.forEach((reaction) => reaction.start()); + for (const reaction of this._reactions) reaction.start(); } teardown() { - this._reactions.forEach((reaction) => reaction.stop()); + for (const reaction of this._reactions) reaction.stop(); } resetStatus() { -- cgit v1.2.3-54-g00ecf