UNPKG

@prezly/theme-kit-core

Version:

Data layer and utility library for developing Prezly themes with JavaScript

31 lines (30 loc) 1.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createStackedCache = createStackedCache; function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); } function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; } function createStackedCache(caches) { return { get(key, latestVersion) { return _asyncToGenerator(function* () { for (var i = 0; i < caches.length; i += 1) { var value = yield caches[i].get(key, latestVersion); if (value !== undefined) { return value; } } return undefined; })(); }, set(key, value, version) { return _asyncToGenerator(function* () { yield Promise.all(caches.map(cache => cache.set(key, value, version))); })(); }, namespace(namespace) { return createStackedCache(caches.map(cache => cache.namespace(namespace))); } }; }