UNPKG

dreamstate

Version:

Store management library based on react context and observers

1 lines 1.63 kB
import{DreamstateError as t}from"../error/DreamstateError.js";import{throwOutOfScope as r}from"../error/throw.js";import{SCOPE_SYMBOL as o}from"../internals.js";import{getReactContext as e}from"./getReactContext.js";import{shouldObserversUpdate as i}from"./shouldObserversUpdate.js";import{processComputed as n}from"../storing/processComputed.js";import{EDreamstateErrorCode as s}from"../../types/error.js";import{isFunction as c}from"../../utils/typechecking.js";var f=function(){function f(t){this.IS_DISPOSED=!1,this.context={},n(this.context)}return f.getDefaultContext=function(){return null},Object.defineProperty(f,"REACT_CONTEXT",{get:function(){if(this===f)throw new t(s.RESTRICTED_OPERATION,"Direct references to ContextManager statics forbidden.");return e(this)},enumerable:!1,configurable:!0}),f.prototype.onProvisionStarted=function(){},f.prototype.onProvisionEnded=function(){},f.prototype.getScope=function(){if(this[o])return this[o];r()},f.prototype.forceUpdate=function(){this.context=n(Object.assign({},this.context)),this[o]&&this[o].INTERNAL.notifyObservers(this)},f.prototype.setContext=function(t){var r=Object.assign({},this.context,c(t)?t(this.context):t);this.context=n(r),this[o]&&i(this[o].INTERNAL.REGISTRY.CONTEXT_STATES_REGISTRY.get(this.constructor),r)&&this[o].INTERNAL.notifyObservers(this)},f.prototype.emitSignal=function(t){if(this[o])return this[o].emitSignal(t,this.constructor);r()},f.prototype.queryDataAsync=function(t){if(this[o])return this[o].queryDataAsync(t);r()},f.prototype.queryDataSync=function(t){if(this[o])return this[o].queryDataSync(t);r()},f}();export{f as ContextManager};