diff options
author | Dan Finlay <542863+danfinlay@users.noreply.github.com> | 2018-03-15 02:27:24 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-15 02:27:24 +0800 |
commit | 19b553907c08bad7a56f4851f683031e6795912a (patch) | |
tree | 4461cb8d1f552b3c1bbdac7cd7cd1fcdcbad6d17 | |
parent | 9226de6c9502b78b0558540759b664d9e571996d (diff) | |
parent | 6aef2ed0b26861b3402e13d4e2a7e401ac3e99c8 (diff) | |
download | tangerine-wallet-browser-19b553907c08bad7a56f4851f683031e6795912a.tar tangerine-wallet-browser-19b553907c08bad7a56f4851f683031e6795912a.tar.gz tangerine-wallet-browser-19b553907c08bad7a56f4851f683031e6795912a.tar.bz2 tangerine-wallet-browser-19b553907c08bad7a56f4851f683031e6795912a.tar.lz tangerine-wallet-browser-19b553907c08bad7a56f4851f683031e6795912a.tar.xz tangerine-wallet-browser-19b553907c08bad7a56f4851f683031e6795912a.tar.zst tangerine-wallet-browser-19b553907c08bad7a56f4851f683031e6795912a.zip |
Merge pull request #3565 from MetaMask/local-store-fix
Fix local store promisification
-rw-r--r-- | app/scripts/lib/local-store.js | 32 | ||||
-rw-r--r-- | development/genStates.js | 2 | ||||
-rw-r--r-- | development/run-version-bump.js | 2 | ||||
-rw-r--r-- | test/unit/development/version–bump-test.js | 4 |
4 files changed, 31 insertions, 9 deletions
diff --git a/app/scripts/lib/local-store.js b/app/scripts/lib/local-store.js index 1cf00dd30..5b47985f6 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() { @@ -11,9 +10,6 @@ module.exports = class ExtensionStore { if (!this.isSupported) { 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) } async get() { @@ -31,6 +27,34 @@ module.exports = class ExtensionStore { async set(state) { return this._set(state) } + + _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) + } + }) + }) + } + + _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) { 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)) }) }) - - |