@acaprojects/a2-composer
Version:
Angular 2 Interface for composer
56 lines • 2.81 kB
JavaScript
import { PRIMITIVE, ServiceMessageBrokerFactory } from '@angular/platform-webworker';
var DataStoreBroker = (function () {
function DataStoreBroker(ref) {
if (!DataStoreBroker.broker) {
DataStoreBroker.broker = ref.injector.get(ServiceMessageBrokerFactory)
.createMessageBroker('COMPOSER Storage Broker');
this.registerLocalStorage();
this.registerSessionStorage();
}
}
DataStoreBroker.prototype.registerLocalStorage = function () {
if (localStorage) {
DataStoreBroker.broker.registerMethod('localStorage_getItem', [PRIMITIVE], function (key) {
return new Promise(function (res) { return res(localStorage.getItem(key)); });
}, PRIMITIVE);
DataStoreBroker.broker.registerMethod('localStorage_setItem', [PRIMITIVE], function (key, value) {
return new Promise(function (res) { return res(localStorage.setItem(key, value)); });
}, PRIMITIVE);
DataStoreBroker.broker.registerMethod('localStorage_removeItem', [PRIMITIVE], function (key) {
return new Promise(function (res) { return res(localStorage.removeItem(key)); });
}, PRIMITIVE);
DataStoreBroker.broker.registerMethod('localStorage_keys', [PRIMITIVE], function (key) {
return new Promise(function (res) {
var keys = [];
for (var i = 0; i < localStorage.length; i++) {
keys.push(localStorage.key(i));
}
res(keys);
});
}, PRIMITIVE);
}
};
DataStoreBroker.prototype.registerSessionStorage = function () {
if (sessionStorage) {
DataStoreBroker.broker.registerMethod('sessionStorage_getItem', [PRIMITIVE], function (key) {
return new Promise(function (res) { return res(sessionStorage.getItem(key)); });
}, PRIMITIVE);
DataStoreBroker.broker.registerMethod('sessionStorage_setItem', [PRIMITIVE], function (key, value) {
return new Promise(function (res) { return res(sessionStorage.setItem(key, value)); });
}, PRIMITIVE);
DataStoreBroker.broker.registerMethod('sessionStorage_keys', [PRIMITIVE], function (key) {
return new Promise(function (res) {
var keys = [];
for (var i = 0; i < sessionStorage.length; i++) {
keys.push(sessionStorage.key(i));
}
res(keys);
});
}, PRIMITIVE);
}
};
return DataStoreBroker;
}());
export { DataStoreBroker };
DataStoreBroker.broker = null;
//# sourceMappingURL=data-store.broker.js.map