@scripty/react-store
Version:
This lightweight global react hook store is inspired by the extjs store architecture. Share your stores through your application with only a few lines of code!
32 lines (25 loc) • 675 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getStore = exports.addStore = void 0;
var addStore = function addStore(store, name) {
if (!window.globalStorage.data.some(function (storage) {
return storage.name === name;
})) {
window.globalStorage.data.push(store);
}
return window.globalStorage;
};
exports.addStore = addStore;
var getStore = function getStore(store, name) {
return store.data.map(function (rec) {
if (rec.name === name) {
return rec;
}
return [];
}).filter(function (rec) {
return Object.keys(rec).length > 0 || rec.length > 0;
})[0];
};
exports.getStore = getStore;