diff options
| author | siikamiika <siikamiika@users.noreply.github.com> | 2020-04-05 15:32:57 +0300 | 
|---|---|---|
| committer | siikamiika <siikamiika@users.noreply.github.com> | 2020-04-05 20:03:45 +0300 | 
| commit | abd056e5637be5cca3033296843dd442593c73e7 (patch) | |
| tree | de84a71d783d408817a877277f5f752b654ab81b | |
| parent | 31a326fe636683e71fa61f11ed25b4f2adaead44 (diff) | |
reduce code duplication
| -rw-r--r-- | ext/fg/js/popup-proxy.js | 28 | 
1 files changed, 15 insertions, 13 deletions
| 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);          }      } |