From 481983aae873d1fb7cceef2cb42ec4fb0580368a Mon Sep 17 00:00:00 2001 From: kumavis Date: Wed, 14 Mar 2018 10:31:25 -0700 Subject: [PATCH 1/4] local-store - fix promisification of methods --- app/scripts/lib/local-store.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/scripts/lib/local-store.js b/app/scripts/lib/local-store.js index 1cf00dd30..2d6155dbf 100644 --- a/app/scripts/lib/local-store.js +++ b/app/scripts/lib/local-store.js @@ -3,7 +3,6 @@ // https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/storage/local const extension = require('extensionizer') -const { promisify } = require('util') module.exports = class ExtensionStore { constructor() { @@ -12,8 +11,8 @@ module.exports = class ExtensionStore { log.error('Storage local API not available.') } const local = extension.storage.local - this._get = promisify(local.get).bind(local) - this._set = promisify(local.set).bind(local) + this._get = function() { return new Promise((resolve) => local.get(resolve)) } + this._set = function(state) { return new Promise((resolve) => local.set(state, resolve)) } } async get() { From 39a831e2a08c1dfe6b80edc129a3ace8a2831824 Mon Sep 17 00:00:00 2001 From: kumavis Date: Wed, 14 Mar 2018 10:32:55 -0700 Subject: [PATCH 2/4] deps - use pify instead of util.promisify --- development/genStates.js | 2 +- development/run-version-bump.js | 2 +- test/unit/development/version–bump-test.js | 4 +--- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/development/genStates.js b/development/genStates.js index d92e2bc2e..bc274c757 100644 --- a/development/genStates.js +++ b/development/genStates.js @@ -1,6 +1,6 @@ const fs = require('fs') const path = require('path') -const { promisify } = require('util') +const promisify = require('pify') start().catch(console.error) diff --git a/development/run-version-bump.js b/development/run-version-bump.js index fde14566e..98757f58e 100644 --- a/development/run-version-bump.js +++ b/development/run-version-bump.js @@ -1,4 +1,4 @@ -const { promisify } = require('util') +const promisify = require('pify') const fs = require('fs') const readFile = promisify(fs.readFile) const writeFile = promisify(fs.writeFile) diff --git a/test/unit/development/version–bump-test.js b/test/unit/development/version–bump-test.js index 1c445c8b4..5e37d4410 100644 --- a/test/unit/development/version–bump-test.js +++ b/test/unit/development/version–bump-test.js @@ -1,6 +1,6 @@ const assert = require('assert') const versionBump = require('../../../development/version-bump') -const { promisify } = require('util') +const promisify = require('pify') const fs = require('fs') const readFile = promisify(fs.readFile) const path = require('path') @@ -41,5 +41,3 @@ describe('version bumper', function () { assert.ok(result.changelog.includes(expected)) }) }) - - From c4e90c9359de3b4c54622bde3f396bc753c9cffb Mon Sep 17 00:00:00 2001 From: kumavis Date: Wed, 14 Mar 2018 10:49:54 -0700 Subject: [PATCH 3/4] local-store - check for error from extension.runtime --- app/scripts/lib/local-store.js | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/app/scripts/lib/local-store.js b/app/scripts/lib/local-store.js index 2d6155dbf..175126d86 100644 --- a/app/scripts/lib/local-store.js +++ b/app/scripts/lib/local-store.js @@ -10,9 +10,6 @@ module.exports = class ExtensionStore { if (!this.isSupported) { log.error('Storage local API not available.') } - const local = extension.storage.local - this._get = function() { return new Promise((resolve) => local.get(resolve)) } - this._set = function(state) { return new Promise((resolve) => local.set(state, resolve)) } } async get() { @@ -30,6 +27,34 @@ module.exports = class ExtensionStore { async set(state) { return this._set(state) } + + function _get() { + const local = extension.storage.local + return new Promise((resolve, reject) => { + local.get(null, (result) => { + const err = extension.runtime.lastError + if (err) { + reject(err) + } else { + resolve(result) + } + }) + }) + } + + function _set(obj) { + const local = extension.storage.local + return new Promise((resolve, reject) => { + local.set(obj, () => { + const err = extension.runtime.lastError + if (err) { + reject(err) + } else { + resolve() + } + }) + }) + } } function isEmpty(obj) { From 6aef2ed0b26861b3402e13d4e2a7e401ac3e99c8 Mon Sep 17 00:00:00 2001 From: kumavis Date: Wed, 14 Mar 2018 10:59:47 -0700 Subject: [PATCH 4/4] local-store - fix class syntax --- app/scripts/lib/local-store.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/scripts/lib/local-store.js b/app/scripts/lib/local-store.js index 175126d86..5b47985f6 100644 --- a/app/scripts/lib/local-store.js +++ b/app/scripts/lib/local-store.js @@ -28,7 +28,7 @@ module.exports = class ExtensionStore { return this._set(state) } - function _get() { + _get() { const local = extension.storage.local return new Promise((resolve, reject) => { local.get(null, (result) => { @@ -42,7 +42,7 @@ module.exports = class ExtensionStore { }) } - function _set(obj) { + _set(obj) { const local = extension.storage.local return new Promise((resolve, reject) => { local.set(obj, () => {