From 26f84c5852638fb52daf4a4a898d62de4a3157b6 Mon Sep 17 00:00:00 2001 From: tophf Date: Tue, 23 May 2017 22:31:40 +0300 Subject: [PATCH] play safe in *Safe() as BG gets defined only in .then --- messaging.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/messaging.js b/messaging.js index 063f4a2a..c11e1f4c 100644 --- a/messaging.js +++ b/messaging.js @@ -272,13 +272,13 @@ function sessionStorageHash(name) { } -function onBackgroundReady(...dataPassthru) { - return BG ? Promise.resolve(...dataPassthru) : new Promise(ping); +function onBackgroundReady() { + return BG ? Promise.resolve() : new Promise(ping); function ping(resolve) { chrome.runtime.sendMessage({method: 'healthCheck'}, health => { if (health !== undefined) { BG = chrome.extension.getBackgroundPage(); - resolve(...dataPassthru); + resolve(); } else { ping(resolve); } @@ -289,13 +289,14 @@ function onBackgroundReady(...dataPassthru) { // in case Chrome haven't yet loaded the bg page and displays our page like edit/manage function getStylesSafe(options) { - return onBackgroundReady(options).then(BG.getStyles); + return onBackgroundReady() + .then(() => BG.getStyles(options)); } function saveStyleSafe(style) { - return onBackgroundReady(BG.deepCopy(style)) - .then(BG.saveStyle) + return onBackgroundReady() + .then(() => BG.saveStyle(BG.deepCopy(style))) .then(savedStyle => { if (style.notify === false) { handleUpdate(savedStyle, style); @@ -306,8 +307,8 @@ function saveStyleSafe(style) { function deleteStyleSafe({id, notify = true} = {}) { - return onBackgroundReady({id, notify}) - .then(BG.deleteStyle) + return onBackgroundReady() + .then(() => BG.deleteStyle({id, notify})) .then(() => { if (!notify) { handleDelete(id);