ayanami
Version:
A better way to react with state
54 lines (53 loc) • 1.85 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Ayanami = void 0;
var rxjs_1 = require("rxjs");
var ikari_1 = require("./ikari");
var ssr_module_1 = require("../ssr/ssr-module");
var flag_1 = require("../ssr/flag");
var globalScope = typeof self !== 'undefined'
? self
: typeof window !== 'undefined'
? window
: typeof global !== 'undefined'
? global
: {};
var Ayanami = /** @class */ (function () {
function Ayanami() {
var _this = this;
// @internal
this.ssrLoadKey = Symbol('SSR_LOADED');
if (!flag_1.isSSREnabled()) {
var name_1 = Object.getPrototypeOf(this)[ssr_module_1.moduleNameKey];
if (!name_1) {
return;
}
// @ts-ignore
var globalCache = globalScope[ssr_module_1.globalKey];
if (globalCache) {
var moduleCache_1 = globalCache[name_1];
if (moduleCache_1) {
Reflect.defineMetadata(this.ssrLoadKey, true, this);
Object.defineProperty(this, 'defaultState', {
get: function () { return moduleCache_1[_this.scopeName]; },
set: rxjs_1.noop,
});
}
}
}
}
Ayanami.prototype.destroy = function () {
ikari_1.destroyIkariFrom(this);
};
Ayanami.prototype.getState$ = function () {
return ikari_1.combineWithIkari(this).state.state$;
};
Ayanami.prototype.getState = function () {
return ikari_1.combineWithIkari(this).state.getState();
};
Ayanami.prototype.getActions = function () {
return ikari_1.combineWithIkari(this).effectActionFactories;
};
return Ayanami;
}());
exports.Ayanami = Ayanami;