From abd056e5637be5cca3033296843dd442593c73e7 Mon Sep 17 00:00:00 2001 From: siikamiika Date: Sun, 5 Apr 2020 15:32:57 +0300 Subject: reduce code duplication --- ext/fg/js/popup-proxy.js | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'ext') diff --git a/ext/fg/js/popup-proxy.js b/ext/fg/js/popup-proxy.js index 7405b552..f1618c9f 100644 --- a/ext/fg/js/popup-proxy.js +++ b/ext/fg/js/popup-proxy.js @@ -132,24 +132,26 @@ class PopupProxy { } this._frameOffsetPromise = this._getFrameOffset(); + + const handleOffset = (offset) => { + this._frameOffset = offset !== null ? offset : [0, 0]; + this._frameOffsetUpdatedAt = Date.now(); + this._frameOffsetPromise = null; + }; + + const handleError = (e) => { + console.error(e); + this._frameOffsetPromise = null; + }; + if (firstRun) { try { - const offset = await this._frameOffsetPromise; - this._frameOffset = offset !== null ? offset : [0, 0]; - this._frameOffsetUpdatedAt = Date.now(); + handleOffset(await this._frameOffsetPromise); } catch (e) { - console.error(e); + handleError(e); } - this._frameOffsetPromise = null; } else { - this._frameOffsetPromise.then((offset) => { - this._frameOffset = offset !== null ? offset : [0, 0]; - this._frameOffsetUpdatedAt = Date.now(); - this._frameOffsetPromise = null; - }, (e) => { - console.error(e); - this._frameOffsetPromise = null; - }); + this._frameOffsetPromise.then(handleOffset, handleError); } } -- cgit v1.2.3