@shopgate/pwa-common
Version:
Common library for the Shopgate Connect PWA.
53 lines (50 loc) • 1.26 kB
JavaScript
/**
* Class to maintain the persisted redux reducers.
*/
let PersistedReducers = /*#__PURE__*/function () {
/**
* Constructor.
*/
function PersistedReducers() {
this.reducers = [];
}
/**
* Returns all reducers.
* @return {Array}
*/
var _proto = PersistedReducers.prototype;
_proto.getAll = function getAll() {
return this.reducers;
}
/**
* Sets a new reducers to be persisted.
* @param {string|Array} reducer The name of the reducer to persist.
* @return {PersistedReducers}
*/;
_proto.set = function set(reducer) {
if (Array.isArray(reducer)) {
reducer.forEach(red => {
if (!this.reducers.includes(red)) {
this.reducers.push(red);
}
});
return this;
}
if (this.reducers.includes(reducer)) {
return this;
}
this.reducers.push(reducer);
return this;
}
/**
* Removes a reducer from the list of persisted reducers.
* @param {string} reducer The name of the reducer to remove.
* @return {PersistedReducers}
*/;
_proto.remove = function remove(reducer) {
this.reducers = this.reducers.filter(red => red !== reducer);
return this;
};
return PersistedReducers;
}();
export default new PersistedReducers();