reduce code duplication

This commit is contained in:
siikamiika 2020-04-05 15:32:57 +03:00
parent 31a326fe63
commit abd056e563

View File

@ -132,24 +132,26 @@ class PopupProxy {
} }
this._frameOffsetPromise = this._getFrameOffset(); 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) { if (firstRun) {
try { try {
const offset = await this._frameOffsetPromise; handleOffset(await this._frameOffsetPromise);
this._frameOffset = offset !== null ? offset : [0, 0];
this._frameOffsetUpdatedAt = Date.now();
} catch (e) { } catch (e) {
console.error(e); handleError(e);
} }
this._frameOffsetPromise = null;
} else { } else {
this._frameOffsetPromise.then((offset) => { this._frameOffsetPromise.then(handleOffset, handleError);
this._frameOffset = offset !== null ? offset : [0, 0];
this._frameOffsetUpdatedAt = Date.now();
this._frameOffsetPromise = null;
}, (e) => {
console.error(e);
this._frameOffsetPromise = null;
});
} }
} }