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();
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);
}
}