CARVIEW |
Select Language
HTTP/2 301
location: https://raw.githubusercontent.com/nbubna/store/master/src/store.async.js
accept-ranges: bytes
age: 0
date: Tue, 22 Jul 2025 04:47:51 GMT
via: 1.1 varnish
x-served-by: cache-bom-vanm7210043-BOM
x-cache: MISS
x-cache-hits: 0
x-timer: S1753159670.432700,VS0,VE947
vary: Accept-Encoding
x-fastly-request-id: 45251896698d21525decc996d7378c20c0ce9b3e
content-length: 0
HTTP/2 200
cache-control: max-age=300
content-security-policy: default-src 'none'; style-src 'unsafe-inline'; sandbox
content-type: text/plain; charset=utf-8
etag: W/"d6bf9269942eaf0731e2e644f55589a28d53e73f02aef58bf656a0a72dbd8fd5"
strict-transport-security: max-age=31536000
x-content-type-options: nosniff
x-frame-options: deny
x-xss-protection: 1; mode=block
x-github-request-id: 107F:23CA67:38013:95E8C:687F17F3
content-encoding: gzip
accept-ranges: bytes
date: Tue, 22 Jul 2025 04:47:51 GMT
via: 1.1 varnish
x-served-by: cache-bom-vanm7210060-BOM
x-cache: MISS
x-cache-hits: 0
x-timer: S1753159671.428899,VS0,VE260
vary: Authorization,Accept-Encoding
access-control-allow-origin: *
cross-origin-resource-policy: cross-origin
x-fastly-request-id: 3b8e66b354000f93a4338ac6aaae42755a2e59d4
expires: Tue, 22 Jul 2025 04:52:51 GMT
source-age: 0
content-length: 837
/**
* Copyright (c) 2019 ESHA Research
* Dual licensed under the MIT and GPL licenses:
* https://www.opensource.org/licenses/mit-license.php
* https://www.gnu.org/licenses/gpl.html
*
* Adds an 'async' duplicate on all store APIs that
* performs storage-related operations asynchronously and returns
* a promise.
*
* Status: BETA - works great, but lacks justification for existence
*/
;(function(window, _) {
var dontPromisify = ['async', 'area', 'namespace', 'isFake', 'toString'];
_.promisify = function(api) {
var async = api.async = _.Store(api._id, api._area, api._ns);
async._async = true;
Object.keys(api).forEach(function(name) {
if (name.charAt(0) !== '_' && dontPromisify.indexOf(name) < 0) {
var fn = api[name];
if (typeof fn === "function") {
async[name] = _.promiseFn(name, fn, api);
}
}
});
return async;
};
_.promiseFn = function(name, fn, self) {
return function promised() {
var args = arguments;
return new Promise(function(resolve, reject) {
setTimeout(function() {
try {
resolve(fn.apply(self, args));
} catch (e) {
reject(e);
}
}, 0);
});
};
};
// promisify existing apis
for (var apiName in _.apis) {
_.promisify(_.apis[apiName]);
}
// ensure future apis are promisified
Object.defineProperty(_.storeAPI, 'async', {
enumerable: true,
configurable: true,
get: function() {
var async = _.promisify(this);
// overwrite getter to avoid re-promisifying
Object.defineProperty(this, 'async', {
enumerable: true,
value: async
});
return async;
}
});
})(window, window.store._);