зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1654587 - [devtools] Remove now-unused async-storage and async-store-helper modules. r=jdescottes,nchevobbe
Differential Revision: https://phabricator.services.mozilla.com/D91737
This commit is contained in:
Родитель
ccb945702d
Коммит
afb3e68613
|
@ -15,7 +15,7 @@
|
|||
"byName": {},
|
||||
"byBlocks": {},
|
||||
"usedIds": {
|
||||
"0": 0
|
||||
"1": 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,7 @@
|
|||
"byName": {},
|
||||
"byBlocks": {},
|
||||
"usedIds": {
|
||||
"0": 0
|
||||
"1": 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -57,7 +57,7 @@
|
|||
"byName": {},
|
||||
"byBlocks": {},
|
||||
"usedIds": {
|
||||
"0": 0
|
||||
"1": 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -99,7 +99,7 @@
|
|||
"byName": {},
|
||||
"byBlocks": {},
|
||||
"usedIds": {
|
||||
"0": 0
|
||||
"1": 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -120,7 +120,7 @@
|
|||
"byName": {},
|
||||
"byBlocks": {},
|
||||
"usedIds": {
|
||||
"0": 0
|
||||
"1": 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -141,7 +141,7 @@
|
|||
"byName": {},
|
||||
"byBlocks": {},
|
||||
"usedIds": {
|
||||
"0": 0
|
||||
"1": 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1300,7 +1300,7 @@
|
|||
"byName": {},
|
||||
"byBlocks": {},
|
||||
"usedIds": {
|
||||
"1": 1
|
||||
"0": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4502,10 +4502,6 @@ const KeyShortcuts = __webpack_require__(541);
|
|||
|
||||
const EventEmitter = __webpack_require__(537);
|
||||
|
||||
const asyncStorage = __webpack_require__(543);
|
||||
|
||||
const asyncStoreHelper = __webpack_require__(549);
|
||||
|
||||
const Telemetry = __webpack_require__(545);
|
||||
|
||||
const {
|
||||
|
@ -4521,8 +4517,6 @@ const saveAs = __webpack_require__(548);
|
|||
module.exports = {
|
||||
KeyShortcuts,
|
||||
PrefsHelper,
|
||||
asyncStorage,
|
||||
asyncStoreHelper,
|
||||
EventEmitter,
|
||||
Telemetry,
|
||||
getUnicodeHostname,
|
||||
|
@ -5028,219 +5022,6 @@ module.exports = KeyShortcuts;
|
|||
|
||||
/***/ }),
|
||||
|
||||
/***/ 543:
|
||||
/***/ (function(module, exports, __webpack_require__) {
|
||||
|
||||
"use strict";
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
|
||||
|
||||
/**
|
||||
*
|
||||
* Adapted from https://github.com/mozilla-b2g/gaia/blob/f09993563fb5fec4393eb71816ce76cb00463190/shared/js/async_storage.js
|
||||
* (converted to use Promises instead of callbacks).
|
||||
*
|
||||
* This file defines an asynchronous version of the localStorage API, backed by
|
||||
* an IndexedDB database. It creates a global asyncStorage object that has
|
||||
* methods like the localStorage object.
|
||||
*
|
||||
* To store a value use setItem:
|
||||
*
|
||||
* asyncStorage.setItem("key", "value");
|
||||
*
|
||||
* This returns a promise in case you want confirmation that the value has been stored.
|
||||
*
|
||||
* asyncStorage.setItem("key", "newvalue").then(function() {
|
||||
* console.log("new value stored");
|
||||
* });
|
||||
*
|
||||
* To read a value, call getItem(), but note that you must wait for a promise
|
||||
* resolution for the value to be retrieved.
|
||||
*
|
||||
* asyncStorage.getItem("key").then(function(value) {
|
||||
* console.log("The value of key is:", value);
|
||||
* });
|
||||
*
|
||||
* Note that unlike localStorage, asyncStorage does not allow you to store and
|
||||
* retrieve values by setting and querying properties directly. You cannot just
|
||||
* write asyncStorage.key; you have to explicitly call setItem() or getItem().
|
||||
*
|
||||
* removeItem(), clear(), length(), and key() are like the same-named methods of
|
||||
* localStorage, and all return a promise.
|
||||
*
|
||||
* The asynchronous nature of getItem() makes it tricky to retrieve multiple
|
||||
* values. But unlike localStorage, asyncStorage does not require the values you
|
||||
* store to be strings. So if you need to save multiple values and want to
|
||||
* retrieve them together, in a single asynchronous operation, just group the
|
||||
* values into a single object. The properties of this object may not include
|
||||
* DOM elements, but they may include things like Blobs and typed arrays.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
const DBNAME = "devtools-async-storage";
|
||||
const DBVERSION = 1;
|
||||
const STORENAME = "keyvaluepairs";
|
||||
var db = null;
|
||||
|
||||
function withStore(type, onsuccess, onerror) {
|
||||
if (db) {
|
||||
const transaction = db.transaction(STORENAME, type);
|
||||
const store = transaction.objectStore(STORENAME);
|
||||
onsuccess(store);
|
||||
} else {
|
||||
const openreq = indexedDB.open(DBNAME, DBVERSION);
|
||||
|
||||
openreq.onerror = function withStoreOnError() {
|
||||
onerror();
|
||||
};
|
||||
|
||||
openreq.onupgradeneeded = function withStoreOnUpgradeNeeded() {
|
||||
// First time setup: create an empty object store
|
||||
openreq.result.createObjectStore(STORENAME);
|
||||
};
|
||||
|
||||
openreq.onsuccess = function withStoreOnSuccess() {
|
||||
db = openreq.result;
|
||||
const transaction = db.transaction(STORENAME, type);
|
||||
const store = transaction.objectStore(STORENAME);
|
||||
onsuccess(store);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function getItem(itemKey) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let req;
|
||||
withStore("readonly", store => {
|
||||
store.transaction.oncomplete = function onComplete() {
|
||||
let value = req.result;
|
||||
|
||||
if (value === undefined) {
|
||||
value = null;
|
||||
}
|
||||
|
||||
resolve(value);
|
||||
};
|
||||
|
||||
req = store.get(itemKey);
|
||||
|
||||
req.onerror = function getItemOnError() {
|
||||
reject("Error in asyncStorage.getItem(): ", req.error.name);
|
||||
};
|
||||
}, reject);
|
||||
});
|
||||
}
|
||||
|
||||
function setItem(itemKey, value) {
|
||||
return new Promise((resolve, reject) => {
|
||||
withStore("readwrite", store => {
|
||||
store.transaction.oncomplete = resolve;
|
||||
const req = store.put(value, itemKey);
|
||||
|
||||
req.onerror = function setItemOnError() {
|
||||
reject("Error in asyncStorage.setItem(): ", req.error.name);
|
||||
};
|
||||
}, reject);
|
||||
});
|
||||
}
|
||||
|
||||
function removeItem(itemKey) {
|
||||
return new Promise((resolve, reject) => {
|
||||
withStore("readwrite", store => {
|
||||
store.transaction.oncomplete = resolve;
|
||||
const req = store.delete(itemKey);
|
||||
|
||||
req.onerror = function removeItemOnError() {
|
||||
reject("Error in asyncStorage.removeItem(): ", req.error.name);
|
||||
};
|
||||
}, reject);
|
||||
});
|
||||
}
|
||||
|
||||
function clear() {
|
||||
return new Promise((resolve, reject) => {
|
||||
withStore("readwrite", store => {
|
||||
store.transaction.oncomplete = resolve;
|
||||
const req = store.clear();
|
||||
|
||||
req.onerror = function clearOnError() {
|
||||
reject("Error in asyncStorage.clear(): ", req.error.name);
|
||||
};
|
||||
}, reject);
|
||||
});
|
||||
}
|
||||
|
||||
function length() {
|
||||
return new Promise((resolve, reject) => {
|
||||
let req;
|
||||
withStore("readonly", store => {
|
||||
store.transaction.oncomplete = function onComplete() {
|
||||
resolve(req.result);
|
||||
};
|
||||
|
||||
req = store.count();
|
||||
|
||||
req.onerror = function lengthOnError() {
|
||||
reject("Error in asyncStorage.length(): ", req.error.name);
|
||||
};
|
||||
}, reject);
|
||||
});
|
||||
}
|
||||
|
||||
function key(n) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (n < 0) {
|
||||
resolve(null);
|
||||
return;
|
||||
}
|
||||
|
||||
let req;
|
||||
withStore("readonly", store => {
|
||||
store.transaction.oncomplete = function onComplete() {
|
||||
const cursor = req.result;
|
||||
resolve(cursor ? cursor.key : null);
|
||||
};
|
||||
|
||||
let advanced = false;
|
||||
req = store.openCursor();
|
||||
|
||||
req.onsuccess = function keyOnSuccess() {
|
||||
const cursor = req.result;
|
||||
|
||||
if (!cursor) {
|
||||
// this means there weren"t enough keys
|
||||
return;
|
||||
}
|
||||
|
||||
if (n === 0 || advanced) {
|
||||
// Either 1) we have the first key, return it if that's what they
|
||||
// wanted, or 2) we"ve got the nth key.
|
||||
return;
|
||||
} // Otherwise, ask the cursor to skip ahead n records
|
||||
|
||||
|
||||
advanced = true;
|
||||
cursor.advance(n);
|
||||
};
|
||||
|
||||
req.onerror = function keyOnError() {
|
||||
reject("Error in asyncStorage.key(): ", req.error.name);
|
||||
};
|
||||
}, reject);
|
||||
});
|
||||
}
|
||||
|
||||
exports.getItem = getItem;
|
||||
exports.setItem = setItem;
|
||||
exports.removeItem = removeItem;
|
||||
exports.clear = clear;
|
||||
exports.length = length;
|
||||
exports.key = key;
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 545:
|
||||
/***/ (function(module, exports) {
|
||||
|
||||
|
@ -5865,66 +5646,6 @@ module.exports = () => {};
|
|||
|
||||
/***/ }),
|
||||
|
||||
/***/ 549:
|
||||
/***/ (function(module, exports, __webpack_require__) {
|
||||
|
||||
"use strict";
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
|
||||
|
||||
|
||||
const asyncStorage = __webpack_require__(543);
|
||||
/*
|
||||
* asyncStoreHelper wraps asyncStorage so that it is easy to define project
|
||||
* specific properties. It is similar to PrefsHelper.
|
||||
*
|
||||
* e.g.
|
||||
* const asyncStore = asyncStoreHelper("r", {a: "_a"})
|
||||
* asyncStore.a // => asyncStorage.getItem("r._a")
|
||||
* asyncStore.a = 2 // => asyncStorage.setItem("r._a", 2)
|
||||
*/
|
||||
|
||||
|
||||
function asyncStoreHelper(root, mappings) {
|
||||
let store = {};
|
||||
|
||||
function getMappingKey(key) {
|
||||
return Array.isArray(mappings[key]) ? mappings[key][0] : mappings[key];
|
||||
}
|
||||
|
||||
function getMappingDefaultValue(key) {
|
||||
return Array.isArray(mappings[key]) ? mappings[key][1] : null;
|
||||
}
|
||||
|
||||
Object.keys(mappings).map(key => Object.defineProperty(store, key, {
|
||||
async get() {
|
||||
const value = await asyncStorage.getItem(`${root}.${getMappingKey(key)}`);
|
||||
return value || getMappingDefaultValue(key);
|
||||
},
|
||||
|
||||
set(value) {
|
||||
return asyncStorage.setItem(`${root}.${getMappingKey(key)}`, value);
|
||||
}
|
||||
|
||||
}));
|
||||
store = new Proxy(store, {
|
||||
set: function (target, property, value, receiver) {
|
||||
if (!mappings.hasOwnProperty(property)) {
|
||||
throw new Error(`AsyncStore: ${property} is not defined in mappings`);
|
||||
}
|
||||
|
||||
Reflect.set(...arguments);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
return store;
|
||||
}
|
||||
|
||||
module.exports = asyncStoreHelper;
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 550:
|
||||
/***/ (function(module, exports, __webpack_require__) {
|
||||
|
||||
|
|
|
@ -5,8 +5,6 @@
|
|||
const { PrefsHelper } = require("./src/prefs");
|
||||
const KeyShortcuts = require("./src/key-shortcuts");
|
||||
const EventEmitter = require("./src/utils/event-emitter");
|
||||
const asyncStorage = require("./src/async-storage");
|
||||
const asyncStoreHelper = require("./src/async-store-helper");
|
||||
const Telemetry = require("./src/utils/telemetry");
|
||||
const { getUnicodeHostname, getUnicodeUrlPath, getUnicodeUrl } =
|
||||
require("./src/unicode-url");
|
||||
|
@ -16,8 +14,6 @@ const saveAs = require("./src/saveAs")
|
|||
module.exports = {
|
||||
KeyShortcuts,
|
||||
PrefsHelper,
|
||||
asyncStorage,
|
||||
asyncStoreHelper,
|
||||
EventEmitter,
|
||||
Telemetry,
|
||||
getUnicodeHostname,
|
||||
|
|
|
@ -1,214 +0,0 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
|
||||
|
||||
/**
|
||||
*
|
||||
* Adapted from https://github.com/mozilla-b2g/gaia/blob/f09993563fb5fec4393eb71816ce76cb00463190/shared/js/async_storage.js
|
||||
* (converted to use Promises instead of callbacks).
|
||||
*
|
||||
* This file defines an asynchronous version of the localStorage API, backed by
|
||||
* an IndexedDB database. It creates a global asyncStorage object that has
|
||||
* methods like the localStorage object.
|
||||
*
|
||||
* To store a value use setItem:
|
||||
*
|
||||
* asyncStorage.setItem("key", "value");
|
||||
*
|
||||
* This returns a promise in case you want confirmation that the value has been stored.
|
||||
*
|
||||
* asyncStorage.setItem("key", "newvalue").then(function() {
|
||||
* console.log("new value stored");
|
||||
* });
|
||||
*
|
||||
* To read a value, call getItem(), but note that you must wait for a promise
|
||||
* resolution for the value to be retrieved.
|
||||
*
|
||||
* asyncStorage.getItem("key").then(function(value) {
|
||||
* console.log("The value of key is:", value);
|
||||
* });
|
||||
*
|
||||
* Note that unlike localStorage, asyncStorage does not allow you to store and
|
||||
* retrieve values by setting and querying properties directly. You cannot just
|
||||
* write asyncStorage.key; you have to explicitly call setItem() or getItem().
|
||||
*
|
||||
* removeItem(), clear(), length(), and key() are like the same-named methods of
|
||||
* localStorage, and all return a promise.
|
||||
*
|
||||
* The asynchronous nature of getItem() makes it tricky to retrieve multiple
|
||||
* values. But unlike localStorage, asyncStorage does not require the values you
|
||||
* store to be strings. So if you need to save multiple values and want to
|
||||
* retrieve them together, in a single asynchronous operation, just group the
|
||||
* values into a single object. The properties of this object may not include
|
||||
* DOM elements, but they may include things like Blobs and typed arrays.
|
||||
*
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const DBNAME = "devtools-async-storage";
|
||||
const DBVERSION = 1;
|
||||
const STORENAME = "keyvaluepairs";
|
||||
var db = null;
|
||||
|
||||
function withStore(type, onsuccess, onerror) {
|
||||
if (db) {
|
||||
const transaction = db.transaction(STORENAME, type);
|
||||
const store = transaction.objectStore(STORENAME);
|
||||
onsuccess(store);
|
||||
} else {
|
||||
const openreq = indexedDB.open(DBNAME, DBVERSION);
|
||||
openreq.onerror = function withStoreOnError() {
|
||||
onerror();
|
||||
};
|
||||
openreq.onupgradeneeded = function withStoreOnUpgradeNeeded() {
|
||||
// First time setup: create an empty object store
|
||||
openreq.result.createObjectStore(STORENAME);
|
||||
};
|
||||
openreq.onsuccess = function withStoreOnSuccess() {
|
||||
db = openreq.result;
|
||||
const transaction = db.transaction(STORENAME, type);
|
||||
const store = transaction.objectStore(STORENAME);
|
||||
onsuccess(store);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function getItem(itemKey) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let req;
|
||||
withStore(
|
||||
"readonly",
|
||||
store => {
|
||||
store.transaction.oncomplete = function onComplete() {
|
||||
let value = req.result;
|
||||
if (value === undefined) {
|
||||
value = null;
|
||||
}
|
||||
resolve(value);
|
||||
};
|
||||
req = store.get(itemKey);
|
||||
req.onerror = function getItemOnError() {
|
||||
reject("Error in asyncStorage.getItem(): ", req.error.name);
|
||||
};
|
||||
},
|
||||
reject
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
function setItem(itemKey, value) {
|
||||
return new Promise((resolve, reject) => {
|
||||
withStore(
|
||||
"readwrite",
|
||||
store => {
|
||||
store.transaction.oncomplete = resolve;
|
||||
const req = store.put(value, itemKey);
|
||||
req.onerror = function setItemOnError() {
|
||||
reject("Error in asyncStorage.setItem(): ", req.error.name);
|
||||
};
|
||||
},
|
||||
reject
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
function removeItem(itemKey) {
|
||||
return new Promise((resolve, reject) => {
|
||||
withStore(
|
||||
"readwrite",
|
||||
store => {
|
||||
store.transaction.oncomplete = resolve;
|
||||
const req = store.delete(itemKey);
|
||||
req.onerror = function removeItemOnError() {
|
||||
reject("Error in asyncStorage.removeItem(): ", req.error.name);
|
||||
};
|
||||
},
|
||||
reject
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
function clear() {
|
||||
return new Promise((resolve, reject) => {
|
||||
withStore(
|
||||
"readwrite",
|
||||
store => {
|
||||
store.transaction.oncomplete = resolve;
|
||||
const req = store.clear();
|
||||
req.onerror = function clearOnError() {
|
||||
reject("Error in asyncStorage.clear(): ", req.error.name);
|
||||
};
|
||||
},
|
||||
reject
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
function length() {
|
||||
return new Promise((resolve, reject) => {
|
||||
let req;
|
||||
withStore(
|
||||
"readonly",
|
||||
store => {
|
||||
store.transaction.oncomplete = function onComplete() {
|
||||
resolve(req.result);
|
||||
};
|
||||
req = store.count();
|
||||
req.onerror = function lengthOnError() {
|
||||
reject("Error in asyncStorage.length(): ", req.error.name);
|
||||
};
|
||||
},
|
||||
reject
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
function key(n) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (n < 0) {
|
||||
resolve(null);
|
||||
return;
|
||||
}
|
||||
|
||||
let req;
|
||||
withStore(
|
||||
"readonly",
|
||||
store => {
|
||||
store.transaction.oncomplete = function onComplete() {
|
||||
const cursor = req.result;
|
||||
resolve(cursor ? cursor.key : null);
|
||||
};
|
||||
let advanced = false;
|
||||
req = store.openCursor();
|
||||
req.onsuccess = function keyOnSuccess() {
|
||||
const cursor = req.result;
|
||||
if (!cursor) {
|
||||
// this means there weren"t enough keys
|
||||
return;
|
||||
}
|
||||
if (n === 0 || advanced) {
|
||||
// Either 1) we have the first key, return it if that's what they
|
||||
// wanted, or 2) we"ve got the nth key.
|
||||
return;
|
||||
}
|
||||
|
||||
// Otherwise, ask the cursor to skip ahead n records
|
||||
advanced = true;
|
||||
cursor.advance(n);
|
||||
};
|
||||
req.onerror = function keyOnError() {
|
||||
reject("Error in asyncStorage.key(): ", req.error.name);
|
||||
};
|
||||
},
|
||||
reject
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
exports.getItem = getItem;
|
||||
exports.setItem = setItem;
|
||||
exports.removeItem = removeItem;
|
||||
exports.clear = clear;
|
||||
exports.length = length;
|
||||
exports.key = key;
|
|
@ -1,57 +0,0 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
|
||||
|
||||
"use strict";
|
||||
|
||||
const asyncStorage = require("./async-storage");
|
||||
|
||||
/*
|
||||
* asyncStoreHelper wraps asyncStorage so that it is easy to define project
|
||||
* specific properties. It is similar to PrefsHelper.
|
||||
*
|
||||
* e.g.
|
||||
* const asyncStore = asyncStoreHelper("r", {a: "_a"})
|
||||
* asyncStore.a // => asyncStorage.getItem("r._a")
|
||||
* asyncStore.a = 2 // => asyncStorage.setItem("r._a", 2)
|
||||
*/
|
||||
function asyncStoreHelper(root, mappings) {
|
||||
let store = {};
|
||||
|
||||
function getMappingKey(key) {
|
||||
return Array.isArray(mappings[key]) ? mappings[key][0] : mappings[key];
|
||||
}
|
||||
|
||||
function getMappingDefaultValue(key) {
|
||||
return Array.isArray(mappings[key]) ? mappings[key][1] : null;
|
||||
}
|
||||
|
||||
Object.keys(mappings).map(key =>
|
||||
Object.defineProperty(store, key, {
|
||||
async get() {
|
||||
const value = await asyncStorage.getItem(
|
||||
`${root}.${getMappingKey(key)}`
|
||||
);
|
||||
return value || getMappingDefaultValue(key);
|
||||
},
|
||||
set(value) {
|
||||
return asyncStorage.setItem(`${root}.${getMappingKey(key)}`, value);
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
store = new Proxy(store, {
|
||||
set: function(target, property, value, receiver) {
|
||||
if (!mappings.hasOwnProperty(property)) {
|
||||
throw new Error(`AsyncStore: ${property} is not defined in mappings`);
|
||||
}
|
||||
|
||||
Reflect.set(...arguments);
|
||||
return true;
|
||||
},
|
||||
});
|
||||
|
||||
return store;
|
||||
}
|
||||
|
||||
module.exports = asyncStoreHelper;
|
|
@ -1,45 +0,0 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
|
||||
|
||||
// @flow
|
||||
|
||||
import { asyncStorage, asyncStoreHelper } from "devtools-modules";
|
||||
|
||||
function mockAsyncStorage() {
|
||||
const store = {};
|
||||
jest.spyOn(asyncStorage, "getItem");
|
||||
jest.spyOn(asyncStorage, "setItem");
|
||||
|
||||
asyncStorage.getItem.mockImplementation(key => store[key]);
|
||||
asyncStorage.setItem.mockImplementation((key, value) => (store[key] = value));
|
||||
}
|
||||
|
||||
describe("asycStoreHelper", () => {
|
||||
it("can get and set values", async () => {
|
||||
mockAsyncStorage();
|
||||
const asyncStore = asyncStoreHelper("root", { a: "_a" });
|
||||
asyncStore.a = 3;
|
||||
expect(await asyncStore.a).toEqual(3);
|
||||
});
|
||||
|
||||
it("supports default values", async () => {
|
||||
mockAsyncStorage();
|
||||
const asyncStore = asyncStoreHelper("root", { a: ["_a", {}] });
|
||||
expect(await asyncStore.a).toEqual({});
|
||||
});
|
||||
|
||||
it("undefined default value", async () => {
|
||||
mockAsyncStorage();
|
||||
const asyncStore = asyncStoreHelper("root", { a: "_a" });
|
||||
expect(await asyncStore.a).toEqual(null);
|
||||
});
|
||||
|
||||
it("setting an undefined mapping", async () => {
|
||||
mockAsyncStorage();
|
||||
const asyncStore = asyncStoreHelper("root", { a: "_a" });
|
||||
expect(() => {
|
||||
asyncStore.b = 3;
|
||||
}).toThrow("AsyncStore: b is not defined");
|
||||
});
|
||||
});
|
|
@ -69,8 +69,6 @@ const VENDORS = [
|
|||
|
||||
const moduleMapping = {
|
||||
Telemetry: "devtools/client/shared/telemetry",
|
||||
asyncStoreHelper: "devtools/client/shared/async-store-helper",
|
||||
asyncStorage: "devtools/shared/async-storage",
|
||||
PluralForm: "devtools/shared/plural-form",
|
||||
DevToolsUtils: "devtools/shared/DevToolsUtils",
|
||||
AppConstants: "resource://gre/modules/AppConstants.jsm",
|
||||
|
|
Загрузка…
Ссылка в новой задаче