ayanami
Version:
A better way to react with state
51 lines (50 loc) • 1.72 kB
JavaScript
import { noop } from 'rxjs';
import { combineWithIkari, destroyIkariFrom } from './ikari';
import { moduleNameKey, globalKey } from '../ssr/ssr-module';
import { isSSREnabled } from '../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 (!isSSREnabled()) {
var name_1 = Object.getPrototypeOf(this)[moduleNameKey];
if (!name_1) {
return;
}
// @ts-ignore
var globalCache = globalScope[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: noop,
});
}
}
}
}
Ayanami.prototype.destroy = function () {
destroyIkariFrom(this);
};
Ayanami.prototype.getState$ = function () {
return combineWithIkari(this).state.state$;
};
Ayanami.prototype.getState = function () {
return combineWithIkari(this).state.getState();
};
Ayanami.prototype.getActions = function () {
return combineWithIkari(this).effectActionFactories;
};
return Ayanami;
}());
export { Ayanami };