UNPKG

reactant-share

Version:

A framework for building shared web applications with Reactant

45 lines (42 loc) 1.75 kB
import { __extends, __assign, __decorate, __param, __metadata } from '../node_modules/tslib/tslib.es6.js'; import { injectable, inject } from 'reactant'; import { StorageOptions, Storage } from 'reactant-storage'; export { REHYDRATE, StorageOptions, getRehydrated } from 'reactant-storage'; import { PortDetector } from './portDetector.js'; import { storageModuleName } from '../constants.js'; var ReactantStorage = /** @class */ (function (_super) { __extends(ReactantStorage, _super); function ReactantStorage(portDetector, options) { var _this = _super.call(this, options) || this; _this.portDetector = portDetector; _this.options = options; _this.onRehydrated(function () { _this.portDetector.onServer(function () { _this.persist(); }); _this.portDetector.onClient(function () { _this.pause(); }); if (_this.portDetector.isServer) { _this.portDetector.syncToClients(); } }); return _this; } /** * set module to storage persistent */ ReactantStorage.prototype.setStorage = function (target, options) { return _super.prototype.setStorage.call(this, target, this.options.disableClientRehydrated && this.portDetector.isClient ? __assign(__assign({}, options), { blacklist: [], whitelist: [] }) : options); }; ReactantStorage = __decorate([ injectable({ name: storageModuleName, }), __param(1, inject(StorageOptions)), __metadata("design:paramtypes", [PortDetector, Object]) ], ReactantStorage); return ReactantStorage; }(Storage)); export { ReactantStorage as Storage };