Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

stated-bean

Package Overview
Dependencies
Maintainers
2
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stated-bean - npm Package Compare versions

Comparing version 0.8.0 to 0.8.1

2

CHANGELOG.md

@@ -5,2 +5,4 @@ # Changelog

### [0.8.1](https://github.com/mjolnirjs/stated-bean/compare/v0.8.0...v0.8.1) (2019-10-15)
## [0.8.0](https://github.com/mjolnirjs/stated-bean/compare/v0.7.0...v0.8.0) (2019-10-13)

@@ -7,0 +9,0 @@

27

lib/cjs.js

@@ -56,3 +56,2 @@ 'use strict';

this._beanFactory = new DefaultBeanFactory();
this._debug = false;
}

@@ -66,8 +65,2 @@ StatedBeanApplication.prototype.getBeanFactory = function () {

};
StatedBeanApplication.prototype.setDebug = function (_debug) {
this._debug = _debug;
};
StatedBeanApplication.prototype.isDebug = function () {
return this._debug;
};
return StatedBeanApplication;

@@ -771,3 +764,4 @@ }());

}
return container.register(new BeanDefinition(beanProvider));
// Subscribing to the bean makes it not destroyed
container.register(new BeanDefinition(beanProvider)).state$.subscribe();
});

@@ -819,3 +813,3 @@ return container;

};
emitEffectAction_1({ loading: true, data: null, error: null });
emitEffectAction_1({ loading: true, error: null });
var result = originalMethod.apply(this, args);

@@ -825,12 +819,15 @@ if (isPromise(result)) {

.then(function (data) {
emitEffectAction_1({ loading: false, data: data, error: null });
emitEffectAction_1({ data: data });
return data;
})
.catch(function (e) {
emitEffectAction_1({ loading: false, data: null, error: e });
emitEffectAction_1({ loading: false, error: e });
throw e;
})
.finally(function () {
emitEffectAction_1({ loading: false });
});
}
else {
emitEffectAction_1({ loading: false, data: result, error: null });
emitEffectAction_1({ loading: false, data: result });
}

@@ -963,5 +960,2 @@ return result;

}
else {
throw new Error('invalid UseBeanOptions');
}
}

@@ -1018,6 +1012,5 @@ var beanChangeListener = React.useCallback(function (_action) {

var beanChangeListener = React.useCallback(function (action) {
var field = action.fieldMeta.name;
if (observedFields == null ||
observedFields.length === 0 ||
observedFields.includes(field)) {
observedFields.includes(action.fieldMeta.name)) {
setVersion(function (prev) { return prev + 1; });

@@ -1024,0 +1017,0 @@ }

@@ -1,1 +0,1 @@

"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var statedBeanContext,React=require("react"),React__default=_interopDefault(React),rxjs=require("rxjs"),tslib=require("tslib");function getStatedBeanContext(){return statedBeanContext||(statedBeanContext=React__default.createContext({})),statedBeanContext}var StatedBeanConsumer=function(e){var t=e.children,n=getStatedBeanContext();return React__default.createElement(n.Consumer,null,(function(e){return t(e)}))},DefaultBeanFactory=function(){function e(){}return e.prototype.createBean=function(e){return e.isFactoryBean?e.getFactory()(e.props):new e.beanType(e.props)},e.prototype.destroyBean=function(){},e}(),StatedBeanApplication=function(){function e(){this._beanFactory=new DefaultBeanFactory,this._debug=!1}return e.prototype.getBeanFactory=function(){return this._beanFactory},e.prototype.setBeanFactory=function(e){return this._beanFactory=e,this},e.prototype.setDebug=function(e){this._debug=e},e.prototype.isDebug=function(){return this._debug},e}(),StatedBeanClass=Symbol("stated-bean-class"),StatedBeanWrapper=Symbol("stated-bean-wrapper"),ForceUpdate=Symbol("stated-bean-force-update");function isFunction(e){return"function"==typeof e}function isStatedBeanClass(e){return Object.hasOwnProperty.call(e,StatedBeanClass)}function getBeanWrapper(e){if(Object.hasOwnProperty.call(e,StatedBeanWrapper))return Reflect.get(e,StatedBeanWrapper)}function isPromise(e){return!!e&&"function"==typeof e.then}function getPropertiesWithoutFunction(e){if(e)return Object.keys(e).filter((function(t){return"function"!=typeof e[t]}))}var CountableSubject=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t._counter$=new rxjs.Subject,t}return tslib.__extends(t,e),t.prototype._subscribe=function(t){var n=this,r=new rxjs.Observable((function(t){var r=e.prototype._subscribe.call(n,t);return function(){r.unsubscribe(),n._counter$.next(n.observers.length)}})).subscribe(t);return this._counter$.next(this.observers.length),r},t.prototype.subscribeCount=function(e){this._counter$.subscribe(e)},t.prototype.complete=function(){e.prototype.complete.call(this),this._counter$.complete()},t}(rxjs.Subject),BeanWrapper=function(){function e(e){this._beanObserver=e,this.state$=new CountableSubject}return Object.defineProperty(e.prototype,"beanObserver",{get:function(){return this._beanObserver},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"beanDefinition",{get:function(){return this.beanObserver.beanDefinition},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"beanMeta",{get:function(){return this.beanDefinition.beanMeta},enumerable:!0,configurable:!0}),e.prototype.forceUpdate=function(e){var t=(this.beanMeta.statedFields||[]).find((function(t){return t.name===e}));void 0!==t&&this.beanObserver.publishStateAction(t,this.beanObserver.proxy[e])},e}();function getProperty(e,t){if(t in e)return e[t]}function isInitializingBean(e){var t=getProperty(e,"afterProvided");return void 0!==t&&"function"==typeof t}function isDisposableBean(e){var t=getProperty(e,"destroy");return void 0!==t&&"function"==typeof t}function isBeanContainerAware(e){var t=getProperty(e,"setBeanContainer");return void 0!==t&&"function"==typeof t}var BeanObserver=function(){function e(e,t,n){this._bean=e,this._container=t,this._beanDefinition=n,this.state$=new CountableSubject,this.effect$=new rxjs.Subject,this.props$=new rxjs.Subject,this._proxyBean=new Proxy(this.origin,{});var r=this._observe();this._stateSubscription=r.state$.subscribe(this.state$),isBeanContainerAware(this.proxy)&&this.proxy.setBeanContainer(this._container)}return Object.defineProperty(e.prototype,"beanDefinition",{get:function(){return this._beanDefinition},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"proxy",{get:function(){return this._proxyBean},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"origin",{get:function(){return this._bean},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"beanMeta",{get:function(){return this.beanDefinition.beanMeta},enumerable:!0,configurable:!0}),e.prototype.destroy=function(){this.state$.complete(),this.effect$.complete(),isDisposableBean(this.proxy)&&this.proxy.destroy(),void 0!==this._stateSubscription&&this._stateSubscription.unsubscribe()},e.prototype.publishStateAction=function(e,t){var n={bean:this.proxy,nextValue:t,prevValue:this.proxy[e.name],fieldMeta:e};this.state$.next(n)},e.prototype._observe=function(){var e=this,t=this._defineStatedBean(this.proxy),n=this.beanMeta.propsFields;return void 0!==n&&(n.forEach((function(t){e._initPropsField(e.proxy,t,e.beanDefinition.props)})),this.props$.subscribe((function(t){n.forEach((function(n){e._updatePropsField(e.proxy,n,t)}))}))),setTimeout((function(){null!=e.beanMeta.postMethod&&void 0!==e.beanMeta.postMethod.descriptor?e.beanMeta.postMethod.descriptor.value.apply(e.proxy):isInitializingBean(e.proxy)&&e.proxy.afterProvided()}),0),t},e.prototype._defineStatedBean=function(e){var t=this,n=getBeanWrapper(e);void 0===n&&(n=new BeanWrapper(this),Object.defineProperty(e,StatedBeanWrapper,{value:n}),(this.beanMeta.statedFields||[]).forEach((function(r){t._observeBeanField(n,e,r)})));return n},e.prototype._observeBeanField=function(e,t,n){var r=Symbol(n.name.toString()+"_v");Object.defineProperty(t,r,{writable:!0,value:t[n.name]}),Object.defineProperty(t,n.name.toString(),{set:function(o){t[r]=o;var a={bean:t,nextValue:o,prevValue:t[n.name],fieldMeta:n};e.state$.next(a)},get:function(){return t[r]}})},e.prototype._initPropsField=function(e,t,n){var r=void 0===n?void 0:n[t.prop];t.observable?Reflect.set(e,t.name,new rxjs.BehaviorSubject(r)):Reflect.set(e,t.name,r)},e.prototype._updatePropsField=function(e,t,n){var r=void 0===n?void 0:n[t.prop],o=Reflect.get(e,t.name);if(t.observable){var a=o;Object.is(a.getValue(),r)||a.next(r)}else Object.is(o,r)||Reflect.set(e,t.name,r)},e}(),StatedBeanRegistry=function(){function e(e){this._container=e,this._typedBeans=new WeakMap,this._namedBeans=new Map}return Object.defineProperty(e.prototype,"beanFactory",{get:function(){return this._container.application.getBeanFactory()},enumerable:!0,configurable:!0}),e.prototype.getTypedBean=function(e){return this._typedBeans.get(e)},e.prototype.getNamedBean=function(e){return this._namedBeans.get(e)},e.prototype.register=function(e){if(e.isNamedBean)return this.registerNamedBean(e);var t=this.createBeanObserver(e);return this._addTypedBean(e.beanType,t),t},e.prototype.registerNamedBean=function(e){var t=this.getNamedBean(e.beanName);if(void 0!==t)return t;var n=this.createBeanObserver(e);return this._namedBeans.set(e.beanName,n),this._addTypedBean(e.beanType,n),n},e.prototype.createBeanObserver=function(e){var t=this,n=this.beanFactory.createBean(e);e.setTarget(n);var r=new BeanObserver(n,this._container,e);r.state$.subscribeCount((function(e){0===e&&(t.remove(r),r.destroy())}));var o=getBeanWrapper(n);return void 0!==o&&o.state$.subscribeCount((function(r){0===r&&(t.beanFactory.destroyBean(e,n),o.state$.complete())})),r},e.prototype.remove=function(e){var t=e.beanDefinition;this._namedBeans.delete(t.beanName);var n=this._typedBeans.get(t.beanType);if(void 0!==n){var r=n.indexOf(e);n.splice(r,1)}},e.prototype._addTypedBean=function(e,t){var n=this._typedBeans.get(e);void 0===n?this._typedBeans.set(e,[t]):n.unshift(t)},e}(),StatedBeanContainer=function(){function e(e,t){this._parent=e,null!=t?this._app=t:null!=this._parent&&null!=this._parent.application?this._app=this._parent.application:this._app=new StatedBeanApplication,this._registry=new StatedBeanRegistry(this)}return e.prototype.destroy=function(){},e.prototype.getBeanRegistry=function(){return this._registry},e.prototype.getTypedObserver=function(e){var t=this.getBeanRegistry().getTypedBean(e);return null==t&&this.parent&&(t=this.parent.getTypedObserver(e)),t},e.prototype.getNamedObserver=function(e){var t=this.getBeanRegistry().getNamedBean(e);return null==t&&this.parent&&(t=this.parent.getNamedObserver(e)),t},e.prototype.register=function(e){return this.getBeanRegistry().register(e)},Object.defineProperty(e.prototype,"parent",{get:function(){return this._parent},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"application",{get:function(){return this._app},enumerable:!0,configurable:!0}),e}();function boundMethod(e,t,n){var r=n.value;if("function"!=typeof r)throw new TypeError("@boundMethod decorator can only be applied to methods not: "+typeof r);var o=!1;return{configurable:!0,get:function(){if(o||this===e.prototype||Object.hasOwnProperty.call(this,t)||"function"!=typeof r)return r;var n=r.bind(this);return o=!0,Object.defineProperty(this,t,{configurable:!0,get:function(){return n},set:function(e){r=e,delete this[t]}}),o=!1,n},set:function(e){r=e}}}function boundClass(e){var t;return"undefined"!=typeof Reflect&&"function"==typeof Reflect.ownKeys?t=Reflect.ownKeys(e.prototype):(t=Object.getOwnPropertyNames(e.prototype),"function"==typeof Object.getOwnPropertySymbols&&(t=t.concat(Object.getOwnPropertySymbols(e.prototype)))),t.forEach((function(t){if("constructor"!==t){var n=Object.getOwnPropertyDescriptor(e.prototype,t);void 0!==n&&"function"==typeof n.value&&Object.defineProperty(e.prototype,t,boundMethod(e,t,n))}})),e}var StateBeanMetaStorage,StatedBeanMetaStorage=function(){function e(){this._beans=new WeakMap,this._statedFields=new WeakMap,this._propsFields=new WeakMap,this._postMethod=new WeakMap}return e.prototype.collectStatedBean=function(e){var t=e.target,n=this._statedFields.get(t);e.statedFields=n,e.propsFields=this._propsFields.get(t),e.postMethod=this._postMethod.get(t),this._beans.set(t,e),this._statedFields.delete(t),this._propsFields.delete(t),this._postMethod.delete(t)},e.prototype.collectStatedField=function(e){var t=e.target,n=this._statedFields.get(t);n?n.push(e):this._statedFields.set(t,[e])},e.prototype.collectPropsField=function(e){var t=e.target,n=this._propsFields.get(t);n?n.push(e):this._propsFields.set(t,[e])},e.prototype.collectPostProvided=function(e){this._postMethod.set(e.target,e)},e.prototype.getBeanMeta=function(e){return this._beans.get(e)},e.prototype.clear=function(){this._beans=new WeakMap,this._statedFields=new WeakMap,this._propsFields=new WeakMap,this._postMethod=new WeakMap},e}(),getMetadataStorage=function(){return StateBeanMetaStorage||(StateBeanMetaStorage=new StatedBeanMetaStorage)},UN_NAMED_BEAN=Symbol("UN_NAMED_BEAN"),BeanDefinition=function(){function e(e){this._beanProvider=e}return e.prototype.getFactory=function(){return this._beanProvider.factory},e.prototype.getFactoryBeanType=function(){return void 0!==this.target?this.target.constructor:this.beanType},e.prototype.setTarget=function(e){this._target=e,this.isPlainObject&&Object.keys(e).forEach((function(t){"function"==typeof e[t]&&Object.defineProperty(e,t,{value:e[t].bind(e)})}))},Object.defineProperty(e.prototype,"target",{get:function(){return this._target},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"beanType",{get:function(){return this._beanProvider.type},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isSingleton",{get:function(){return!!(this._beanProvider.singleton||this.beanMeta&&this.beanMeta.singleton)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"beanName",{get:function(){var e=this._beanProvider.name||this.beanMeta.name;return this.isSingleton?e||this.beanType.name:e||UN_NAMED_BEAN},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"beanMeta",{get:function(){var e=getMetadataStorage(),t=this.isFactoryBean?this.getFactoryBeanType():this.beanType,n=e.getBeanMeta(t);return void 0===n?{target:t,name:this._beanProvider.name,statedFields:(getPropertiesWithoutFunction(this.target)||[]).map((function(e){return{name:e,target:t}}))}:n},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isNamedBean",{get:function(){return this.beanName!==UN_NAMED_BEAN},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isFactoryBean",{get:function(){return isFunction(this._beanProvider.factory)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isPlainObject",{get:function(){return this.isFactoryBean?"Object"===this.getFactoryBeanType().name:"Object"===this.beanType.name},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"props",{get:function(){return this._beanProvider.props},enumerable:!0,configurable:!0}),e}();function useContainer(e){var t=e.providers,n=e.application,r=getStatedBeanContext(),o=React.useContext(r),a=React.useState((function(){var e=new StatedBeanContainer(o.container,n);return(t||[]).forEach((function(t){var n;return n=isFunction(t)?isStatedBeanClass(t)?{type:t}:{type:t.constructor,factory:t}:t,e.register(new BeanDefinition(n))})),e}))[0];return React.useEffect((function(){return function(){a.destroy()}}),[a]),a}var StatedBeanProvider=function(e){var t=e.providers,n=e.application,r=e.children,o=getStatedBeanContext(),a=useContainer({providers:t,application:n});return React__default.createElement(o.Provider,{value:{container:a}},r)};function Effect(e){return function(t,n,r){void 0===r&&(r=Object.getOwnPropertyDescriptor(t,n));var o=e||n,a=r.value;return r.value=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=getBeanWrapper(this);if(void 0!==n){var r=function(e){var t=n.beanObserver;void 0!==t&&t.effect$.next(tslib.__assign({effect:o},e))};r({loading:!0,data:null,error:null});var i=a.apply(this,e);return isPromise(i)?i.then((function(e){return r({loading:!1,data:e,error:null}),e})).catch((function(e){throw r({loading:!1,data:null,error:e}),e})):(r({loading:!1,data:i,error:null}),i)}return a.apply(this,e)},r}}function ObservableProps(e){return function(t,n){var r=e;void 0===r&&(r=String(n)).endsWith("$")&&(r=r.substring(0,r.length-1)),getMetadataStorage().collectPropsField({name:n,prop:r,target:t.constructor,observable:!0})}}function AfterProvided(){return function(e,t,n){return void 0===n&&(n=Object.getOwnPropertyDescriptor(e,t)),getMetadataStorage().collectPostProvided({name:t,target:e.constructor,descriptor:n}),n}}function Props(e){return function(t,n){getMetadataStorage().collectPropsField({name:n,prop:e||String(n),target:t.constructor,observable:!1})}}function Stated(){return function(e,t){getMetadataStorage().collectStatedField({name:t,target:e.constructor})}}function StatedBean(e){return function(t){var n="object"==typeof e?e.name:e,r="object"==typeof e&&e.singleton;boundClass(t),Object.defineProperty(t,StatedBeanClass,{writable:!1,value:!0}),getMetadataStorage().collectStatedBean({name:n,target:t,singleton:r})}}function useBean(e,t){var n,r,o=getStatedBeanContext(),a=React.useContext(o),i=React.useState(0)[1];if(void 0!==t)if("object"==typeof t)n=t.name,r=t.props;else{if("string"!=typeof t&&"symbol"!=typeof t)throw new Error("invalid UseBeanOptions");n=t}var s=React.useCallback((function(e){i((function(e){return e+1}))}),[]),u=a.container;if(void 0===u)throw new Error("not found stated bean container.");var c=React.useState((function(){var t;if(isFunction(e)&&!isStatedBeanClass(e)){var o=e;t={type:o.constructor,factory:o,name:n,props:r}}else t={type:e,name:n,props:r};return u.register(new BeanDefinition(t))}))[0],p=React.useState((function(){return c.state$.subscribe(s)}))[0];return React.useEffect((function(){c.props$.next(r)}),[r,c]),React.useEffect((function(){return function(){return p.unsubscribe()}}),[p]),c.proxy}function useInject(e){var t=getStatedBeanContext(),n=React.useContext(t),r=React.useState(0)[1],o="object"==typeof e?e.type:e,a="object"==typeof e?e:{},i=a.name,s=a.observedFields,u=React.useCallback((function(e){var t=e.fieldMeta.name;(null==s||0===s.length||s.includes(t))&&r((function(e){return e+1}))}),[s]),c=n.container;if(void 0===c)throw new Error("not found container");var p=React.useState((function(){var e;if(void 0!==i)e=c.getNamedObserver(i);else if(void 0!==o){var t=c.getTypedObserver(o);if(void 0!==t){if(!(t.length<=1))throw new Error("Multiple bean ["+o.name+"] found.");e=t[0]}}return e}))[0];if(void 0===p)throw new Error("bean observer is undefined.");var f=React.useState((function(){return p.state$.subscribe(u)}))[0];return React.useEffect((function(){return function(){f.unsubscribe()}}),[f]),p.proxy}function useObservable(e){var t=React.useState((function(){return e instanceof rxjs.BehaviorSubject?e.getValue():null})),n=t[0],r=t[1],o=React.useState(e),a=o[0],i=o[1];return React.useEffect((function(){isFunction(e)||i(e)}),[e]),React.useEffect((function(){var e;return a instanceof rxjs.Observable&&(e=a.subscribe(r)),function(){e&&e.unsubscribe()}}),[a]),n}function useObserveEffect(e,t){var n=getStatedBeanContext();if(void 0===React.useContext(n).container)throw new Error("not found container");var r=React.useState((function(){return{loading:!1,error:null,data:null,effect:t}})),o=r[0],a=r[1],i=React.useCallback((function(e){e.effect===t&&a(e)}),[t]),s=React.useState((function(){var t=getBeanWrapper(e);if(void 0===t)throw new Error("bean observer is undefined");return t.beanObserver.effect$.subscribe(i)}))[0];return React.useEffect((function(){return function(){s.unsubscribe()}}),[s]),o}exports.AfterProvided=AfterProvided,exports.BeanDefinition=BeanDefinition,exports.BeanObserver=BeanObserver,exports.BeanWrapper=BeanWrapper,exports.DefaultBeanFactory=DefaultBeanFactory,exports.Effect=Effect,exports.ForceUpdate=ForceUpdate,exports.ObservableProps=ObservableProps,exports.Props=Props,exports.Stated=Stated,exports.StatedBean=StatedBean,exports.StatedBeanApplication=StatedBeanApplication,exports.StatedBeanClass=StatedBeanClass,exports.StatedBeanConsumer=StatedBeanConsumer,exports.StatedBeanContainer=StatedBeanContainer,exports.StatedBeanProvider=StatedBeanProvider,exports.StatedBeanWrapper=StatedBeanWrapper,exports.UN_NAMED_BEAN=UN_NAMED_BEAN,exports.boundClass=boundClass,exports.boundMethod=boundMethod,exports.getBeanWrapper=getBeanWrapper,exports.getPropertiesWithoutFunction=getPropertiesWithoutFunction,exports.getProperty=getProperty,exports.getStatedBeanContext=getStatedBeanContext,exports.isBeanContainerAware=isBeanContainerAware,exports.isDisposableBean=isDisposableBean,exports.isFunction=isFunction,exports.isInitializingBean=isInitializingBean,exports.isPromise=isPromise,exports.isStatedBeanClass=isStatedBeanClass,exports.useBean=useBean,exports.useContainer=useContainer,exports.useInject=useInject,exports.useObservable=useObservable,exports.useObserveEffect=useObserveEffect;
"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var statedBeanContext,React=require("react"),React__default=_interopDefault(React),rxjs=require("rxjs"),tslib=require("tslib");function getStatedBeanContext(){return statedBeanContext||(statedBeanContext=React__default.createContext({})),statedBeanContext}var StatedBeanConsumer=function(e){var t=e.children,n=getStatedBeanContext();return React__default.createElement(n.Consumer,null,(function(e){return t(e)}))},DefaultBeanFactory=function(){function e(){}return e.prototype.createBean=function(e){return e.isFactoryBean?e.getFactory()(e.props):new e.beanType(e.props)},e.prototype.destroyBean=function(){},e}(),StatedBeanApplication=function(){function e(){this._beanFactory=new DefaultBeanFactory}return e.prototype.getBeanFactory=function(){return this._beanFactory},e.prototype.setBeanFactory=function(e){return this._beanFactory=e,this},e}(),StatedBeanClass=Symbol("stated-bean-class"),StatedBeanWrapper=Symbol("stated-bean-wrapper"),ForceUpdate=Symbol("stated-bean-force-update");function isFunction(e){return"function"==typeof e}function isStatedBeanClass(e){return Object.hasOwnProperty.call(e,StatedBeanClass)}function getBeanWrapper(e){if(Object.hasOwnProperty.call(e,StatedBeanWrapper))return Reflect.get(e,StatedBeanWrapper)}function isPromise(e){return!!e&&"function"==typeof e.then}function getPropertiesWithoutFunction(e){if(e)return Object.keys(e).filter((function(t){return"function"!=typeof e[t]}))}var CountableSubject=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t._counter$=new rxjs.Subject,t}return tslib.__extends(t,e),t.prototype._subscribe=function(t){var n=this,r=new rxjs.Observable((function(t){var r=e.prototype._subscribe.call(n,t);return function(){r.unsubscribe(),n._counter$.next(n.observers.length)}})).subscribe(t);return this._counter$.next(this.observers.length),r},t.prototype.subscribeCount=function(e){this._counter$.subscribe(e)},t.prototype.complete=function(){e.prototype.complete.call(this),this._counter$.complete()},t}(rxjs.Subject),BeanWrapper=function(){function e(e){this._beanObserver=e,this.state$=new CountableSubject}return Object.defineProperty(e.prototype,"beanObserver",{get:function(){return this._beanObserver},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"beanDefinition",{get:function(){return this.beanObserver.beanDefinition},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"beanMeta",{get:function(){return this.beanDefinition.beanMeta},enumerable:!0,configurable:!0}),e.prototype.forceUpdate=function(e){var t=(this.beanMeta.statedFields||[]).find((function(t){return t.name===e}));void 0!==t&&this.beanObserver.publishStateAction(t,this.beanObserver.proxy[e])},e}();function getProperty(e,t){if(t in e)return e[t]}function isInitializingBean(e){var t=getProperty(e,"afterProvided");return void 0!==t&&"function"==typeof t}function isDisposableBean(e){var t=getProperty(e,"destroy");return void 0!==t&&"function"==typeof t}function isBeanContainerAware(e){var t=getProperty(e,"setBeanContainer");return void 0!==t&&"function"==typeof t}var BeanObserver=function(){function e(e,t,n){this._bean=e,this._container=t,this._beanDefinition=n,this.state$=new CountableSubject,this.effect$=new rxjs.Subject,this.props$=new rxjs.Subject,this._proxyBean=new Proxy(this.origin,{});var r=this._observe();this._stateSubscription=r.state$.subscribe(this.state$),isBeanContainerAware(this.proxy)&&this.proxy.setBeanContainer(this._container)}return Object.defineProperty(e.prototype,"beanDefinition",{get:function(){return this._beanDefinition},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"proxy",{get:function(){return this._proxyBean},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"origin",{get:function(){return this._bean},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"beanMeta",{get:function(){return this.beanDefinition.beanMeta},enumerable:!0,configurable:!0}),e.prototype.destroy=function(){this.state$.complete(),this.effect$.complete(),isDisposableBean(this.proxy)&&this.proxy.destroy(),void 0!==this._stateSubscription&&this._stateSubscription.unsubscribe()},e.prototype.publishStateAction=function(e,t){var n={bean:this.proxy,nextValue:t,prevValue:this.proxy[e.name],fieldMeta:e};this.state$.next(n)},e.prototype._observe=function(){var e=this,t=this._defineStatedBean(this.proxy),n=this.beanMeta.propsFields;return void 0!==n&&(n.forEach((function(t){e._initPropsField(e.proxy,t,e.beanDefinition.props)})),this.props$.subscribe((function(t){n.forEach((function(n){e._updatePropsField(e.proxy,n,t)}))}))),setTimeout((function(){null!=e.beanMeta.postMethod&&void 0!==e.beanMeta.postMethod.descriptor?e.beanMeta.postMethod.descriptor.value.apply(e.proxy):isInitializingBean(e.proxy)&&e.proxy.afterProvided()}),0),t},e.prototype._defineStatedBean=function(e){var t=this,n=getBeanWrapper(e);void 0===n&&(n=new BeanWrapper(this),Object.defineProperty(e,StatedBeanWrapper,{value:n}),(this.beanMeta.statedFields||[]).forEach((function(r){t._observeBeanField(n,e,r)})));return n},e.prototype._observeBeanField=function(e,t,n){var r=Symbol(n.name.toString()+"_v");Object.defineProperty(t,r,{writable:!0,value:t[n.name]}),Object.defineProperty(t,n.name.toString(),{set:function(a){t[r]=a;var o={bean:t,nextValue:a,prevValue:t[n.name],fieldMeta:n};e.state$.next(o)},get:function(){return t[r]}})},e.prototype._initPropsField=function(e,t,n){var r=void 0===n?void 0:n[t.prop];t.observable?Reflect.set(e,t.name,new rxjs.BehaviorSubject(r)):Reflect.set(e,t.name,r)},e.prototype._updatePropsField=function(e,t,n){var r=void 0===n?void 0:n[t.prop],a=Reflect.get(e,t.name);if(t.observable){var o=a;Object.is(o.getValue(),r)||o.next(r)}else Object.is(a,r)||Reflect.set(e,t.name,r)},e}(),StatedBeanRegistry=function(){function e(e){this._container=e,this._typedBeans=new WeakMap,this._namedBeans=new Map}return Object.defineProperty(e.prototype,"beanFactory",{get:function(){return this._container.application.getBeanFactory()},enumerable:!0,configurable:!0}),e.prototype.getTypedBean=function(e){return this._typedBeans.get(e)},e.prototype.getNamedBean=function(e){return this._namedBeans.get(e)},e.prototype.register=function(e){if(e.isNamedBean)return this.registerNamedBean(e);var t=this.createBeanObserver(e);return this._addTypedBean(e.beanType,t),t},e.prototype.registerNamedBean=function(e){var t=this.getNamedBean(e.beanName);if(void 0!==t)return t;var n=this.createBeanObserver(e);return this._namedBeans.set(e.beanName,n),this._addTypedBean(e.beanType,n),n},e.prototype.createBeanObserver=function(e){var t=this,n=this.beanFactory.createBean(e);e.setTarget(n);var r=new BeanObserver(n,this._container,e);r.state$.subscribeCount((function(e){0===e&&(t.remove(r),r.destroy())}));var a=getBeanWrapper(n);return void 0!==a&&a.state$.subscribeCount((function(r){0===r&&(t.beanFactory.destroyBean(e,n),a.state$.complete())})),r},e.prototype.remove=function(e){var t=e.beanDefinition;this._namedBeans.delete(t.beanName);var n=this._typedBeans.get(t.beanType);if(void 0!==n){var r=n.indexOf(e);n.splice(r,1)}},e.prototype._addTypedBean=function(e,t){var n=this._typedBeans.get(e);void 0===n?this._typedBeans.set(e,[t]):n.unshift(t)},e}(),StatedBeanContainer=function(){function e(e,t){this._parent=e,null!=t?this._app=t:null!=this._parent&&null!=this._parent.application?this._app=this._parent.application:this._app=new StatedBeanApplication,this._registry=new StatedBeanRegistry(this)}return e.prototype.destroy=function(){},e.prototype.getBeanRegistry=function(){return this._registry},e.prototype.getTypedObserver=function(e){var t=this.getBeanRegistry().getTypedBean(e);return null==t&&this.parent&&(t=this.parent.getTypedObserver(e)),t},e.prototype.getNamedObserver=function(e){var t=this.getBeanRegistry().getNamedBean(e);return null==t&&this.parent&&(t=this.parent.getNamedObserver(e)),t},e.prototype.register=function(e){return this.getBeanRegistry().register(e)},Object.defineProperty(e.prototype,"parent",{get:function(){return this._parent},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"application",{get:function(){return this._app},enumerable:!0,configurable:!0}),e}();function boundMethod(e,t,n){var r=n.value;if("function"!=typeof r)throw new TypeError("@boundMethod decorator can only be applied to methods not: "+typeof r);var a=!1;return{configurable:!0,get:function(){if(a||this===e.prototype||Object.hasOwnProperty.call(this,t)||"function"!=typeof r)return r;var n=r.bind(this);return a=!0,Object.defineProperty(this,t,{configurable:!0,get:function(){return n},set:function(e){r=e,delete this[t]}}),a=!1,n},set:function(e){r=e}}}function boundClass(e){var t;return"undefined"!=typeof Reflect&&"function"==typeof Reflect.ownKeys?t=Reflect.ownKeys(e.prototype):(t=Object.getOwnPropertyNames(e.prototype),"function"==typeof Object.getOwnPropertySymbols&&(t=t.concat(Object.getOwnPropertySymbols(e.prototype)))),t.forEach((function(t){if("constructor"!==t){var n=Object.getOwnPropertyDescriptor(e.prototype,t);void 0!==n&&"function"==typeof n.value&&Object.defineProperty(e.prototype,t,boundMethod(e,t,n))}})),e}var StateBeanMetaStorage,StatedBeanMetaStorage=function(){function e(){this._beans=new WeakMap,this._statedFields=new WeakMap,this._propsFields=new WeakMap,this._postMethod=new WeakMap}return e.prototype.collectStatedBean=function(e){var t=e.target,n=this._statedFields.get(t);e.statedFields=n,e.propsFields=this._propsFields.get(t),e.postMethod=this._postMethod.get(t),this._beans.set(t,e),this._statedFields.delete(t),this._propsFields.delete(t),this._postMethod.delete(t)},e.prototype.collectStatedField=function(e){var t=e.target,n=this._statedFields.get(t);n?n.push(e):this._statedFields.set(t,[e])},e.prototype.collectPropsField=function(e){var t=e.target,n=this._propsFields.get(t);n?n.push(e):this._propsFields.set(t,[e])},e.prototype.collectPostProvided=function(e){this._postMethod.set(e.target,e)},e.prototype.getBeanMeta=function(e){return this._beans.get(e)},e.prototype.clear=function(){this._beans=new WeakMap,this._statedFields=new WeakMap,this._propsFields=new WeakMap,this._postMethod=new WeakMap},e}(),getMetadataStorage=function(){return StateBeanMetaStorage||(StateBeanMetaStorage=new StatedBeanMetaStorage)},UN_NAMED_BEAN=Symbol("UN_NAMED_BEAN"),BeanDefinition=function(){function e(e){this._beanProvider=e}return e.prototype.getFactory=function(){return this._beanProvider.factory},e.prototype.getFactoryBeanType=function(){return void 0!==this.target?this.target.constructor:this.beanType},e.prototype.setTarget=function(e){this._target=e,this.isPlainObject&&Object.keys(e).forEach((function(t){"function"==typeof e[t]&&Object.defineProperty(e,t,{value:e[t].bind(e)})}))},Object.defineProperty(e.prototype,"target",{get:function(){return this._target},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"beanType",{get:function(){return this._beanProvider.type},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isSingleton",{get:function(){return!!(this._beanProvider.singleton||this.beanMeta&&this.beanMeta.singleton)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"beanName",{get:function(){var e=this._beanProvider.name||this.beanMeta.name;return this.isSingleton?e||this.beanType.name:e||UN_NAMED_BEAN},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"beanMeta",{get:function(){var e=getMetadataStorage(),t=this.isFactoryBean?this.getFactoryBeanType():this.beanType,n=e.getBeanMeta(t);return void 0===n?{target:t,name:this._beanProvider.name,statedFields:(getPropertiesWithoutFunction(this.target)||[]).map((function(e){return{name:e,target:t}}))}:n},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isNamedBean",{get:function(){return this.beanName!==UN_NAMED_BEAN},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isFactoryBean",{get:function(){return isFunction(this._beanProvider.factory)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isPlainObject",{get:function(){return this.isFactoryBean?"Object"===this.getFactoryBeanType().name:"Object"===this.beanType.name},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"props",{get:function(){return this._beanProvider.props},enumerable:!0,configurable:!0}),e}();function useContainer(e){var t=e.providers,n=e.application,r=getStatedBeanContext(),a=React.useContext(r),o=React.useState((function(){var e=new StatedBeanContainer(a.container,n);return(t||[]).forEach((function(t){var n;n=isFunction(t)?isStatedBeanClass(t)?{type:t}:{type:t.constructor,factory:t}:t,e.register(new BeanDefinition(n)).state$.subscribe()})),e}))[0];return React.useEffect((function(){return function(){o.destroy()}}),[o]),o}var StatedBeanProvider=function(e){var t=e.providers,n=e.application,r=e.children,a=getStatedBeanContext(),o=useContainer({providers:t,application:n});return React__default.createElement(a.Provider,{value:{container:o}},r)};function Effect(e){return function(t,n,r){void 0===r&&(r=Object.getOwnPropertyDescriptor(t,n));var a=e||n,o=r.value;return r.value=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=getBeanWrapper(this);if(void 0!==n){var r=function(e){var t=n.beanObserver;void 0!==t&&t.effect$.next(tslib.__assign({effect:a},e))};r({loading:!0,error:null});var i=o.apply(this,e);return isPromise(i)?i.then((function(e){return r({data:e}),e})).catch((function(e){throw r({loading:!1,error:e}),e})).finally((function(){r({loading:!1})})):(r({loading:!1,data:i}),i)}return o.apply(this,e)},r}}function ObservableProps(e){return function(t,n){var r=e;void 0===r&&(r=String(n)).endsWith("$")&&(r=r.substring(0,r.length-1)),getMetadataStorage().collectPropsField({name:n,prop:r,target:t.constructor,observable:!0})}}function AfterProvided(){return function(e,t,n){return void 0===n&&(n=Object.getOwnPropertyDescriptor(e,t)),getMetadataStorage().collectPostProvided({name:t,target:e.constructor,descriptor:n}),n}}function Props(e){return function(t,n){getMetadataStorage().collectPropsField({name:n,prop:e||String(n),target:t.constructor,observable:!1})}}function Stated(){return function(e,t){getMetadataStorage().collectStatedField({name:t,target:e.constructor})}}function StatedBean(e){return function(t){var n="object"==typeof e?e.name:e,r="object"==typeof e&&e.singleton;boundClass(t),Object.defineProperty(t,StatedBeanClass,{writable:!1,value:!0}),getMetadataStorage().collectStatedBean({name:n,target:t,singleton:r})}}function useBean(e,t){var n,r,a=getStatedBeanContext(),o=React.useContext(a),i=React.useState(0)[1];void 0!==t&&("object"==typeof t?(n=t.name,r=t.props):"string"!=typeof t&&"symbol"!=typeof t||(n=t));var s=React.useCallback((function(e){i((function(e){return e+1}))}),[]),u=o.container;if(void 0===u)throw new Error("not found stated bean container.");var c=React.useState((function(){var t;if(isFunction(e)&&!isStatedBeanClass(e)){var a=e;t={type:a.constructor,factory:a,name:n,props:r}}else t={type:e,name:n,props:r};return u.register(new BeanDefinition(t))}))[0],p=React.useState((function(){return c.state$.subscribe(s)}))[0];return React.useEffect((function(){c.props$.next(r)}),[r,c]),React.useEffect((function(){return function(){return p.unsubscribe()}}),[p]),c.proxy}function useInject(e){var t=getStatedBeanContext(),n=React.useContext(t),r=React.useState(0)[1],a="object"==typeof e?e.type:e,o="object"==typeof e?e:{},i=o.name,s=o.observedFields,u=React.useCallback((function(e){(null==s||0===s.length||s.includes(e.fieldMeta.name))&&r((function(e){return e+1}))}),[s]),c=n.container;if(void 0===c)throw new Error("not found container");var p=React.useState((function(){var e;if(void 0!==i)e=c.getNamedObserver(i);else if(void 0!==a){var t=c.getTypedObserver(a);if(void 0!==t){if(!(t.length<=1))throw new Error("Multiple bean ["+a.name+"] found.");e=t[0]}}return e}))[0];if(void 0===p)throw new Error("bean observer is undefined.");var f=React.useState((function(){return p.state$.subscribe(u)}))[0];return React.useEffect((function(){return function(){f.unsubscribe()}}),[f]),p.proxy}function useObservable(e){var t=React.useState((function(){return e instanceof rxjs.BehaviorSubject?e.getValue():null})),n=t[0],r=t[1],a=React.useState(e),o=a[0],i=a[1];return React.useEffect((function(){isFunction(e)||i(e)}),[e]),React.useEffect((function(){var e;return o instanceof rxjs.Observable&&(e=o.subscribe(r)),function(){e&&e.unsubscribe()}}),[o]),n}function useObserveEffect(e,t){var n=getStatedBeanContext();if(void 0===React.useContext(n).container)throw new Error("not found container");var r=React.useState((function(){return{loading:!1,error:null,data:null,effect:t}})),a=r[0],o=r[1],i=React.useCallback((function(e){e.effect===t&&o(e)}),[t]),s=React.useState((function(){var t=getBeanWrapper(e);if(void 0===t)throw new Error("bean observer is undefined");return t.beanObserver.effect$.subscribe(i)}))[0];return React.useEffect((function(){return function(){s.unsubscribe()}}),[s]),a}exports.AfterProvided=AfterProvided,exports.BeanDefinition=BeanDefinition,exports.BeanObserver=BeanObserver,exports.BeanWrapper=BeanWrapper,exports.DefaultBeanFactory=DefaultBeanFactory,exports.Effect=Effect,exports.ForceUpdate=ForceUpdate,exports.ObservableProps=ObservableProps,exports.Props=Props,exports.Stated=Stated,exports.StatedBean=StatedBean,exports.StatedBeanApplication=StatedBeanApplication,exports.StatedBeanClass=StatedBeanClass,exports.StatedBeanConsumer=StatedBeanConsumer,exports.StatedBeanContainer=StatedBeanContainer,exports.StatedBeanProvider=StatedBeanProvider,exports.StatedBeanWrapper=StatedBeanWrapper,exports.UN_NAMED_BEAN=UN_NAMED_BEAN,exports.boundClass=boundClass,exports.boundMethod=boundMethod,exports.getBeanWrapper=getBeanWrapper,exports.getPropertiesWithoutFunction=getPropertiesWithoutFunction,exports.getProperty=getProperty,exports.getStatedBeanContext=getStatedBeanContext,exports.isBeanContainerAware=isBeanContainerAware,exports.isDisposableBean=isDisposableBean,exports.isFunction=isFunction,exports.isInitializingBean=isInitializingBean,exports.isPromise=isPromise,exports.isStatedBeanClass=isStatedBeanClass,exports.useBean=useBean,exports.useContainer=useContainer,exports.useInject=useInject,exports.useObservable=useObservable,exports.useObserveEffect=useObserveEffect;

@@ -10,3 +10,2 @@ import { DefaultBeanFactory } from './StatedBeanFactory';

this._beanFactory = new DefaultBeanFactory();
this._debug = false;
}

@@ -20,8 +19,2 @@ StatedBeanApplication.prototype.getBeanFactory = function () {

};
StatedBeanApplication.prototype.setDebug = function (_debug) {
this._debug = _debug;
};
StatedBeanApplication.prototype.isDebug = function () {
return this._debug;
};
return StatedBeanApplication;

@@ -28,0 +21,0 @@ }());

@@ -30,3 +30,3 @@ import { __assign } from "tslib";

};
emitEffectAction_1({ loading: true, data: null, error: null });
emitEffectAction_1({ loading: true, error: null });
var result = originalMethod.apply(this, args);

@@ -36,12 +36,15 @@ if (isPromise(result)) {

.then(function (data) {
emitEffectAction_1({ loading: false, data: data, error: null });
emitEffectAction_1({ data: data });
return data;
})
.catch(function (e) {
emitEffectAction_1({ loading: false, data: null, error: e });
emitEffectAction_1({ loading: false, error: e });
throw e;
})
.finally(function () {
emitEffectAction_1({ loading: false });
});
}
else {
emitEffectAction_1({ loading: false, data: result, error: null });
emitEffectAction_1({ loading: false, data: result });
}

@@ -48,0 +51,0 @@ return result;

@@ -32,5 +32,2 @@ import { getStatedBeanContext } from '../context';

}
else {
throw new Error('invalid UseBeanOptions');
}
}

@@ -37,0 +34,0 @@ var beanChangeListener = useCallback(function (_action) {

@@ -33,3 +33,4 @@ import { getStatedBeanContext } from '../context/StatedBeanContext';

}
return container.register(new BeanDefinition(beanProvider));
// Subscribing to the bean makes it not destroyed
container.register(new BeanDefinition(beanProvider)).state$.subscribe();
});

@@ -36,0 +37,0 @@ return container;

@@ -18,6 +18,5 @@ import { getStatedBeanContext } from '../context';

var beanChangeListener = useCallback(function (action) {
var field = action.fieldMeta.name;
if (observedFields == null ||
observedFields.length === 0 ||
observedFields.includes(field)) {
observedFields.includes(action.fieldMeta.name)) {
setVersion(function (prev) { return prev + 1; });

@@ -24,0 +23,0 @@ }

@@ -44,3 +44,2 @@ import React, { useContext, useState, useEffect, useCallback } from 'react';

this._beanFactory = new DefaultBeanFactory();
this._debug = false;
}

@@ -54,8 +53,2 @@ getBeanFactory() {

}
setDebug(_debug) {
this._debug = _debug;
}
isDebug() {
return this._debug;
}
}

@@ -666,3 +659,4 @@

}
return container.register(new BeanDefinition(beanProvider));
// Subscribing to the bean makes it not destroyed
container.register(new BeanDefinition(beanProvider)).state$.subscribe();
});

@@ -709,17 +703,20 @@ return container;

};
emitEffectAction({ loading: true, data: null, error: null });
emitEffectAction({ loading: true, error: null });
const result = originalMethod.apply(this, args);
if (isPromise(result)) {
return result
.then((data) => {
emitEffectAction({ loading: false, data, error: null });
.then(data => {
emitEffectAction({ data: data });
return data;
})
.catch((e) => {
emitEffectAction({ loading: false, data: null, error: e });
emitEffectAction({ loading: false, error: e });
throw e;
})
.finally(() => {
emitEffectAction({ loading: false });
});
}
else {
emitEffectAction({ loading: false, data: result, error: null });
emitEffectAction({ loading: false, data: result });
}

@@ -852,5 +849,2 @@ return result;

}
else {
throw new Error('invalid UseBeanOptions');
}
}

@@ -907,6 +901,5 @@ const beanChangeListener = useCallback((_action) => {

const beanChangeListener = useCallback((action) => {
const field = action.fieldMeta.name;
if (observedFields == null ||
observedFields.length === 0 ||
observedFields.includes(field)) {
observedFields.includes(action.fieldMeta.name)) {
setVersion(prev => prev + 1);

@@ -913,0 +906,0 @@ }

@@ -1,1 +0,1 @@

import e,{useContext as t,useState as n,useEffect as r,useCallback as s}from"react";import{Subject as i,Observable as o,BehaviorSubject as a}from"rxjs";let c;function p(){return c||(c=e.createContext({})),c}const u=({children:t})=>{const n=p();return e.createElement(n.Consumer,null,e=>t(e))};class d{createBean(e){if(e.isFactoryBean){return e.getFactory()(e.props)}return new e.beanType(e.props)}destroyBean(){}}class l{constructor(){this._beanFactory=new d,this._debug=!1}getBeanFactory(){return this._beanFactory}setBeanFactory(e){return this._beanFactory=e,this}setDebug(e){this._debug=e}isDebug(){return this._debug}}const h=Symbol("stated-bean-class"),b=Symbol("stated-bean-wrapper"),f=Symbol("stated-bean-force-update");function y(e){return"function"==typeof e}function g(e){return Object.hasOwnProperty.call(e,h)}function _(e){if(Object.hasOwnProperty.call(e,b))return Reflect.get(e,b)}function v(e){return!!e&&"function"==typeof e.then}function m(e){if(e)return Object.keys(e).filter(t=>"function"!=typeof e[t])}class w extends i{constructor(){super(...arguments),this._counter$=new i}_subscribe(e){const t=new o(e=>{const t=super._subscribe(e);return()=>{t.unsubscribe(),this._counter$.next(this.observers.length)}}).subscribe(e);return this._counter$.next(this.observers.length),t}subscribeCount(e){this._counter$.subscribe(e)}complete(){super.complete(),this._counter$.complete()}}class B{constructor(e){this._beanObserver=e,this.state$=new w}get beanObserver(){return this._beanObserver}get beanDefinition(){return this.beanObserver.beanDefinition}get beanMeta(){return this.beanDefinition.beanMeta}forceUpdate(e){const t=(this.beanMeta.statedFields||[]).find(t=>t.name===e);void 0!==t&&this.beanObserver.publishStateAction(t,this.beanObserver.proxy[e])}}function O(e,t){if(t in e)return e[t]}function F(e){const t=O(e,"afterProvided");return void 0!==t&&"function"==typeof t}function M(e){const t=O(e,"destroy");return void 0!==t&&"function"==typeof t}function P(e){const t=O(e,"setBeanContainer");return void 0!==t&&"function"==typeof t}class x{constructor(e,t,n){this._bean=e,this._container=t,this._beanDefinition=n,this.state$=new w,this.effect$=new i,this.props$=new i,this._proxyBean=new Proxy(this.origin,{});const r=this._observe();this._stateSubscription=r.state$.subscribe(this.state$),P(this.proxy)&&this.proxy.setBeanContainer(this._container)}get beanDefinition(){return this._beanDefinition}get proxy(){return this._proxyBean}get origin(){return this._bean}get beanMeta(){return this.beanDefinition.beanMeta}destroy(){this.state$.complete(),this.effect$.complete(),M(this.proxy)&&this.proxy.destroy(),void 0!==this._stateSubscription&&this._stateSubscription.unsubscribe()}publishStateAction(e,t){const n={bean:this.proxy,nextValue:t,prevValue:this.proxy[e.name],fieldMeta:e};this.state$.next(n)}_observe(){const e=this._defineStatedBean(this.proxy),t=this.beanMeta.propsFields;return void 0!==t&&(t.forEach(e=>{this._initPropsField(this.proxy,e,this.beanDefinition.props)}),this.props$.subscribe(e=>{t.forEach(t=>{this._updatePropsField(this.proxy,t,e)})})),setTimeout(()=>{if(null!=this.beanMeta.postMethod&&void 0!==this.beanMeta.postMethod.descriptor){this.beanMeta.postMethod.descriptor.value.apply(this.proxy)}else F(this.proxy)&&this.proxy.afterProvided()},0),e}_defineStatedBean(e){let t=_(e);if(void 0===t){t=new B(this),Object.defineProperty(e,b,{value:t}),(this.beanMeta.statedFields||[]).forEach(n=>{this._observeBeanField(t,e,n)})}return t}_observeBeanField(e,t,n){const r=Symbol(n.name.toString()+"_v");Object.defineProperty(t,r,{writable:!0,value:t[n.name]}),Object.defineProperty(t,n.name.toString(),{set(s){t[r]=s;const i={bean:t,nextValue:s,prevValue:t[n.name],fieldMeta:n};e.state$.next(i)},get:()=>t[r]})}_initPropsField(e,t,n){const r=void 0===n?void 0:n[t.prop];t.observable?Reflect.set(e,t.name,new a(r)):Reflect.set(e,t.name,r)}_updatePropsField(e,t,n){const r=void 0===n?void 0:n[t.prop],s=Reflect.get(e,t.name);if(t.observable){const e=s;Object.is(e.getValue(),r)||e.next(r)}else Object.is(s,r)||Reflect.set(e,t.name,r)}}class j{constructor(e){this._container=e,this._typedBeans=new WeakMap,this._namedBeans=new Map}get beanFactory(){return this._container.application.getBeanFactory()}getTypedBean(e){return this._typedBeans.get(e)}getNamedBean(e){return this._namedBeans.get(e)}register(e){if(e.isNamedBean)return this.registerNamedBean(e);const t=this.createBeanObserver(e);return this._addTypedBean(e.beanType,t),t}registerNamedBean(e){const t=this.getNamedBean(e.beanName);if(void 0!==t)return t;{const t=this.createBeanObserver(e);return this._namedBeans.set(e.beanName,t),this._addTypedBean(e.beanType,t),t}}createBeanObserver(e){const t=this.beanFactory.createBean(e);e.setTarget(t);const n=new x(t,this._container,e);n.state$.subscribeCount(e=>{0===e&&(this.remove(n),n.destroy())});const r=_(t);return void 0!==r&&r.state$.subscribeCount(n=>{0===n&&(this.beanFactory.destroyBean(e,t),r.state$.complete())}),n}remove(e){const t=e.beanDefinition;this._namedBeans.delete(t.beanName);const n=this._typedBeans.get(t.beanType);if(void 0!==n){const t=n.indexOf(e);n.splice(t,1)}}_addTypedBean(e,t){const n=this._typedBeans.get(e);void 0===n?this._typedBeans.set(e,[t]):n.unshift(t)}}class ${constructor(e,t){this._parent=e,null!=t?this._app=t:null!=this._parent&&null!=this._parent.application?this._app=this._parent.application:this._app=new l,this._registry=new j(this)}destroy(){}getBeanRegistry(){return this._registry}getTypedObserver(e){let t=this.getBeanRegistry().getTypedBean(e);return null==t&&this.parent&&(t=this.parent.getTypedObserver(e)),t}getNamedObserver(e){let t=this.getBeanRegistry().getNamedBean(e);return null==t&&this.parent&&(t=this.parent.getNamedObserver(e)),t}register(e){return this.getBeanRegistry().register(e)}get parent(){return this._parent}get application(){return this._app}}function S(e,t,n){let r=n.value;if("function"!=typeof r)throw new TypeError(`@boundMethod decorator can only be applied to methods not: ${typeof r}`);let s=!1;return{configurable:!0,get(){if(s||this===e.prototype||Object.hasOwnProperty.call(this,t)||"function"!=typeof r)return r;const n=r.bind(this);return s=!0,Object.defineProperty(this,t,{configurable:!0,get:()=>n,set(e){r=e,delete this[t]}}),s=!1,n},set(e){r=e}}}function T(e){let t;return"undefined"!=typeof Reflect&&"function"==typeof Reflect.ownKeys?t=Reflect.ownKeys(e.prototype):(t=Object.getOwnPropertyNames(e.prototype),"function"==typeof Object.getOwnPropertySymbols&&(t=t.concat(Object.getOwnPropertySymbols(e.prototype)))),t.forEach(t=>{if("constructor"===t)return;const n=Object.getOwnPropertyDescriptor(e.prototype,t);void 0!==n&&"function"==typeof n.value&&Object.defineProperty(e.prototype,t,S(e,t,n))}),e}class N{constructor(){this._beans=new WeakMap,this._statedFields=new WeakMap,this._propsFields=new WeakMap,this._postMethod=new WeakMap}collectStatedBean(e){const t=e.target,n=this._statedFields.get(t);e.statedFields=n,e.propsFields=this._propsFields.get(t),e.postMethod=this._postMethod.get(t),this._beans.set(t,e),this._statedFields.delete(t),this._propsFields.delete(t),this._postMethod.delete(t)}collectStatedField(e){const t=e.target,n=this._statedFields.get(t);n?n.push(e):this._statedFields.set(t,[e])}collectPropsField(e){const t=e.target,n=this._propsFields.get(t);n?n.push(e):this._propsFields.set(t,[e])}collectPostProvided(e){this._postMethod.set(e.target,e)}getBeanMeta(e){return this._beans.get(e)}clear(){this._beans=new WeakMap,this._statedFields=new WeakMap,this._propsFields=new WeakMap,this._postMethod=new WeakMap}}let E;const D=()=>E||(E=new N),R=Symbol("UN_NAMED_BEAN");class k{constructor(e){this._beanProvider=e}getFactory(){return this._beanProvider.factory}getFactoryBeanType(){return void 0!==this.target?this.target.constructor:this.beanType}setTarget(e){this._target=e,this.isPlainObject&&Object.keys(e).forEach(t=>{"function"==typeof e[t]&&Object.defineProperty(e,t,{value:e[t].bind(e)})})}get target(){return this._target}get beanType(){return this._beanProvider.type}get isSingleton(){return!!(this._beanProvider.singleton||this.beanMeta&&this.beanMeta.singleton)}get beanName(){const e=this._beanProvider.name||this.beanMeta.name;return this.isSingleton?e||this.beanType.name:e||R}get beanMeta(){const e=D(),t=this.isFactoryBean?this.getFactoryBeanType():this.beanType,n=e.getBeanMeta(t);return void 0===n?{target:t,name:this._beanProvider.name,statedFields:(m(this.target)||[]).map(e=>({name:e,target:t}))}:n}get isNamedBean(){return this.beanName!==R}get isFactoryBean(){return y(this._beanProvider.factory)}get isPlainObject(){return this.isFactoryBean?"Object"===this.getFactoryBeanType().name:"Object"===this.beanType.name}get props(){return this._beanProvider.props}}function W({providers:e,application:s}){const i=p(),o=t(i),[a]=n(()=>{const t=new $(o.container,s);return(e||[]).forEach(e=>{let n;return n=y(e)?g(e)?{type:e}:{type:e.constructor,factory:e}:e,t.register(new k(n))}),t});return r(()=>()=>{a.destroy()},[a]),a}const C=({providers:t,application:n,children:r})=>{const s=p(),i=W({providers:t,application:n});return e.createElement(s.Provider,{value:{container:i}},r)};function V(e){return(t,n,r)=>{void 0===r&&(r=Object.getOwnPropertyDescriptor(t,n));const s=e||n,i=r.value;return r.value=function(...e){const t=_(this);if(void 0!==t){const n=e=>{const n=t.beanObserver;void 0!==n&&n.effect$.next(Object.assign({effect:s},e))};n({loading:!0,data:null,error:null});const r=i.apply(this,e);return v(r)?r.then(e=>(n({loading:!1,data:e,error:null}),e)).catch(e=>{throw n({loading:!1,data:null,error:e}),e}):(n({loading:!1,data:r,error:null}),r)}return i.apply(this,e)},r}}function A(e){return(t,n)=>{let r=e;void 0===r&&(r=String(n)).endsWith("$")&&(r=r.substring(0,r.length-1)),D().collectPropsField({name:n,prop:r,target:t.constructor,observable:!0})}}function U(){return(e,t,n)=>(void 0===n&&(n=Object.getOwnPropertyDescriptor(e,t)),D().collectPostProvided({name:t,target:e.constructor,descriptor:n}),n)}function K(e){return(t,n)=>{D().collectPropsField({name:n,prop:e||String(n),target:t.constructor,observable:!1})}}function q(){return(e,t)=>{D().collectStatedField({name:t,target:e.constructor})}}function z(e){return t=>{const n="object"==typeof e?e.name:e,r="object"==typeof e&&e.singleton;T(t),Object.defineProperty(t,h,{writable:!1,value:!0}),D().collectStatedBean({name:n,target:t,singleton:r})}}function G(e,i){const o=p(),a=t(o),[,c]=n(0);let u,d;if(void 0!==i)if("object"==typeof i)u=i.name,d=i.props;else{if("string"!=typeof i&&"symbol"!=typeof i)throw new Error("invalid UseBeanOptions");u=i}const l=s(e=>{c(e=>e+1)},[]),h=a.container;if(void 0===h)throw new Error("not found stated bean container.");const[b]=n(()=>{let t;if(y(e)&&!g(e)){const n=e;t={type:n.constructor,factory:n,name:u,props:d}}else t={type:e,name:u,props:d};return h.register(new k(t))}),[f]=n(()=>b.state$.subscribe(l));return r(()=>{b.props$.next(d)},[d,b]),r(()=>()=>f.unsubscribe(),[f]),b.proxy}function H(e){const i=p(),o=t(i),[,a]=n(0),c="object"==typeof e?e.type:e,{name:u,observedFields:d}="object"==typeof e?e:{},l=s(e=>{const t=e.fieldMeta.name;(null==d||0===d.length||d.includes(t))&&a(e=>e+1)},[d]),h=o.container;if(void 0===h)throw new Error("not found container");const[b]=n(()=>{let e;if(void 0!==u)e=h.getNamedObserver(u);else if(void 0!==c){const t=h.getTypedObserver(c);if(void 0!==t){if(!(t.length<=1))throw new Error(`Multiple bean [${c.name}] found.`);e=t[0]}}return e});if(void 0===b)throw new Error("bean observer is undefined.");const[f]=n(()=>b.state$.subscribe(l));return r(()=>()=>{f.unsubscribe()},[f]),b.proxy}function I(e){const[t,s]=n(()=>e instanceof a?e.getValue():null),[i,c]=n(e);return r(()=>{y(e)||c(e)},[e]),r(()=>{let e;return i instanceof o&&(e=i.subscribe(s)),()=>{e&&e.unsubscribe()}},[i]),t}function J(e,i){const o=p();if(void 0===t(o).container)throw new Error("not found container");const[a,c]=n(()=>({loading:!1,error:null,data:null,effect:i})),u=s(e=>{e.effect===i&&c(e)},[i]),[d]=n(()=>{const t=_(e);if(void 0===t)throw new Error("bean observer is undefined");return t.beanObserver.effect$.subscribe(u)});return r(()=>()=>{d.unsubscribe()},[d]),a}export{U as AfterProvided,k as BeanDefinition,x as BeanObserver,B as BeanWrapper,d as DefaultBeanFactory,V as Effect,f as ForceUpdate,A as ObservableProps,K as Props,q as Stated,z as StatedBean,l as StatedBeanApplication,h as StatedBeanClass,u as StatedBeanConsumer,$ as StatedBeanContainer,C as StatedBeanProvider,b as StatedBeanWrapper,R as UN_NAMED_BEAN,T as boundClass,S as boundMethod,_ as getBeanWrapper,m as getPropertiesWithoutFunction,O as getProperty,p as getStatedBeanContext,P as isBeanContainerAware,M as isDisposableBean,y as isFunction,F as isInitializingBean,v as isPromise,g as isStatedBeanClass,G as useBean,W as useContainer,H as useInject,I as useObservable,J as useObserveEffect};
import e,{useContext as t,useState as n,useEffect as r,useCallback as s}from"react";import{Subject as o,Observable as i,BehaviorSubject as a}from"rxjs";let c;function p(){return c||(c=e.createContext({})),c}const u=({children:t})=>{const n=p();return e.createElement(n.Consumer,null,e=>t(e))};class d{createBean(e){if(e.isFactoryBean){return e.getFactory()(e.props)}return new e.beanType(e.props)}destroyBean(){}}class h{constructor(){this._beanFactory=new d}getBeanFactory(){return this._beanFactory}setBeanFactory(e){return this._beanFactory=e,this}}const l=Symbol("stated-bean-class"),b=Symbol("stated-bean-wrapper"),f=Symbol("stated-bean-force-update");function y(e){return"function"==typeof e}function g(e){return Object.hasOwnProperty.call(e,l)}function v(e){if(Object.hasOwnProperty.call(e,b))return Reflect.get(e,b)}function _(e){return!!e&&"function"==typeof e.then}function m(e){if(e)return Object.keys(e).filter(t=>"function"!=typeof e[t])}class w extends o{constructor(){super(...arguments),this._counter$=new o}_subscribe(e){const t=new i(e=>{const t=super._subscribe(e);return()=>{t.unsubscribe(),this._counter$.next(this.observers.length)}}).subscribe(e);return this._counter$.next(this.observers.length),t}subscribeCount(e){this._counter$.subscribe(e)}complete(){super.complete(),this._counter$.complete()}}class B{constructor(e){this._beanObserver=e,this.state$=new w}get beanObserver(){return this._beanObserver}get beanDefinition(){return this.beanObserver.beanDefinition}get beanMeta(){return this.beanDefinition.beanMeta}forceUpdate(e){const t=(this.beanMeta.statedFields||[]).find(t=>t.name===e);void 0!==t&&this.beanObserver.publishStateAction(t,this.beanObserver.proxy[e])}}function O(e,t){if(t in e)return e[t]}function F(e){const t=O(e,"afterProvided");return void 0!==t&&"function"==typeof t}function M(e){const t=O(e,"destroy");return void 0!==t&&"function"==typeof t}function P(e){const t=O(e,"setBeanContainer");return void 0!==t&&"function"==typeof t}class x{constructor(e,t,n){this._bean=e,this._container=t,this._beanDefinition=n,this.state$=new w,this.effect$=new o,this.props$=new o,this._proxyBean=new Proxy(this.origin,{});const r=this._observe();this._stateSubscription=r.state$.subscribe(this.state$),P(this.proxy)&&this.proxy.setBeanContainer(this._container)}get beanDefinition(){return this._beanDefinition}get proxy(){return this._proxyBean}get origin(){return this._bean}get beanMeta(){return this.beanDefinition.beanMeta}destroy(){this.state$.complete(),this.effect$.complete(),M(this.proxy)&&this.proxy.destroy(),void 0!==this._stateSubscription&&this._stateSubscription.unsubscribe()}publishStateAction(e,t){const n={bean:this.proxy,nextValue:t,prevValue:this.proxy[e.name],fieldMeta:e};this.state$.next(n)}_observe(){const e=this._defineStatedBean(this.proxy),t=this.beanMeta.propsFields;return void 0!==t&&(t.forEach(e=>{this._initPropsField(this.proxy,e,this.beanDefinition.props)}),this.props$.subscribe(e=>{t.forEach(t=>{this._updatePropsField(this.proxy,t,e)})})),setTimeout(()=>{if(null!=this.beanMeta.postMethod&&void 0!==this.beanMeta.postMethod.descriptor){this.beanMeta.postMethod.descriptor.value.apply(this.proxy)}else F(this.proxy)&&this.proxy.afterProvided()},0),e}_defineStatedBean(e){let t=v(e);if(void 0===t){t=new B(this),Object.defineProperty(e,b,{value:t}),(this.beanMeta.statedFields||[]).forEach(n=>{this._observeBeanField(t,e,n)})}return t}_observeBeanField(e,t,n){const r=Symbol(n.name.toString()+"_v");Object.defineProperty(t,r,{writable:!0,value:t[n.name]}),Object.defineProperty(t,n.name.toString(),{set(s){t[r]=s;const o={bean:t,nextValue:s,prevValue:t[n.name],fieldMeta:n};e.state$.next(o)},get:()=>t[r]})}_initPropsField(e,t,n){const r=void 0===n?void 0:n[t.prop];t.observable?Reflect.set(e,t.name,new a(r)):Reflect.set(e,t.name,r)}_updatePropsField(e,t,n){const r=void 0===n?void 0:n[t.prop],s=Reflect.get(e,t.name);if(t.observable){const e=s;Object.is(e.getValue(),r)||e.next(r)}else Object.is(s,r)||Reflect.set(e,t.name,r)}}class j{constructor(e){this._container=e,this._typedBeans=new WeakMap,this._namedBeans=new Map}get beanFactory(){return this._container.application.getBeanFactory()}getTypedBean(e){return this._typedBeans.get(e)}getNamedBean(e){return this._namedBeans.get(e)}register(e){if(e.isNamedBean)return this.registerNamedBean(e);const t=this.createBeanObserver(e);return this._addTypedBean(e.beanType,t),t}registerNamedBean(e){const t=this.getNamedBean(e.beanName);if(void 0!==t)return t;{const t=this.createBeanObserver(e);return this._namedBeans.set(e.beanName,t),this._addTypedBean(e.beanType,t),t}}createBeanObserver(e){const t=this.beanFactory.createBean(e);e.setTarget(t);const n=new x(t,this._container,e);n.state$.subscribeCount(e=>{0===e&&(this.remove(n),n.destroy())});const r=v(t);return void 0!==r&&r.state$.subscribeCount(n=>{0===n&&(this.beanFactory.destroyBean(e,t),r.state$.complete())}),n}remove(e){const t=e.beanDefinition;this._namedBeans.delete(t.beanName);const n=this._typedBeans.get(t.beanType);if(void 0!==n){const t=n.indexOf(e);n.splice(t,1)}}_addTypedBean(e,t){const n=this._typedBeans.get(e);void 0===n?this._typedBeans.set(e,[t]):n.unshift(t)}}class ${constructor(e,t){this._parent=e,null!=t?this._app=t:null!=this._parent&&null!=this._parent.application?this._app=this._parent.application:this._app=new h,this._registry=new j(this)}destroy(){}getBeanRegistry(){return this._registry}getTypedObserver(e){let t=this.getBeanRegistry().getTypedBean(e);return null==t&&this.parent&&(t=this.parent.getTypedObserver(e)),t}getNamedObserver(e){let t=this.getBeanRegistry().getNamedBean(e);return null==t&&this.parent&&(t=this.parent.getNamedObserver(e)),t}register(e){return this.getBeanRegistry().register(e)}get parent(){return this._parent}get application(){return this._app}}function S(e,t,n){let r=n.value;if("function"!=typeof r)throw new TypeError(`@boundMethod decorator can only be applied to methods not: ${typeof r}`);let s=!1;return{configurable:!0,get(){if(s||this===e.prototype||Object.hasOwnProperty.call(this,t)||"function"!=typeof r)return r;const n=r.bind(this);return s=!0,Object.defineProperty(this,t,{configurable:!0,get:()=>n,set(e){r=e,delete this[t]}}),s=!1,n},set(e){r=e}}}function T(e){let t;return"undefined"!=typeof Reflect&&"function"==typeof Reflect.ownKeys?t=Reflect.ownKeys(e.prototype):(t=Object.getOwnPropertyNames(e.prototype),"function"==typeof Object.getOwnPropertySymbols&&(t=t.concat(Object.getOwnPropertySymbols(e.prototype)))),t.forEach(t=>{if("constructor"===t)return;const n=Object.getOwnPropertyDescriptor(e.prototype,t);void 0!==n&&"function"==typeof n.value&&Object.defineProperty(e.prototype,t,S(e,t,n))}),e}class N{constructor(){this._beans=new WeakMap,this._statedFields=new WeakMap,this._propsFields=new WeakMap,this._postMethod=new WeakMap}collectStatedBean(e){const t=e.target,n=this._statedFields.get(t);e.statedFields=n,e.propsFields=this._propsFields.get(t),e.postMethod=this._postMethod.get(t),this._beans.set(t,e),this._statedFields.delete(t),this._propsFields.delete(t),this._postMethod.delete(t)}collectStatedField(e){const t=e.target,n=this._statedFields.get(t);n?n.push(e):this._statedFields.set(t,[e])}collectPropsField(e){const t=e.target,n=this._propsFields.get(t);n?n.push(e):this._propsFields.set(t,[e])}collectPostProvided(e){this._postMethod.set(e.target,e)}getBeanMeta(e){return this._beans.get(e)}clear(){this._beans=new WeakMap,this._statedFields=new WeakMap,this._propsFields=new WeakMap,this._postMethod=new WeakMap}}let E;const D=()=>E||(E=new N),R=Symbol("UN_NAMED_BEAN");class k{constructor(e){this._beanProvider=e}getFactory(){return this._beanProvider.factory}getFactoryBeanType(){return void 0!==this.target?this.target.constructor:this.beanType}setTarget(e){this._target=e,this.isPlainObject&&Object.keys(e).forEach(t=>{"function"==typeof e[t]&&Object.defineProperty(e,t,{value:e[t].bind(e)})})}get target(){return this._target}get beanType(){return this._beanProvider.type}get isSingleton(){return!!(this._beanProvider.singleton||this.beanMeta&&this.beanMeta.singleton)}get beanName(){const e=this._beanProvider.name||this.beanMeta.name;return this.isSingleton?e||this.beanType.name:e||R}get beanMeta(){const e=D(),t=this.isFactoryBean?this.getFactoryBeanType():this.beanType,n=e.getBeanMeta(t);return void 0===n?{target:t,name:this._beanProvider.name,statedFields:(m(this.target)||[]).map(e=>({name:e,target:t}))}:n}get isNamedBean(){return this.beanName!==R}get isFactoryBean(){return y(this._beanProvider.factory)}get isPlainObject(){return this.isFactoryBean?"Object"===this.getFactoryBeanType().name:"Object"===this.beanType.name}get props(){return this._beanProvider.props}}function W({providers:e,application:s}){const o=p(),i=t(o),[a]=n(()=>{const t=new $(i.container,s);return(e||[]).forEach(e=>{let n;n=y(e)?g(e)?{type:e}:{type:e.constructor,factory:e}:e,t.register(new k(n)).state$.subscribe()}),t});return r(()=>()=>{a.destroy()},[a]),a}const C=({providers:t,application:n,children:r})=>{const s=p(),o=W({providers:t,application:n});return e.createElement(s.Provider,{value:{container:o}},r)};function V(e){return(t,n,r)=>{void 0===r&&(r=Object.getOwnPropertyDescriptor(t,n));const s=e||n,o=r.value;return r.value=function(...e){const t=v(this);if(void 0!==t){const n=e=>{const n=t.beanObserver;void 0!==n&&n.effect$.next(Object.assign({effect:s},e))};n({loading:!0,error:null});const r=o.apply(this,e);return _(r)?r.then(e=>(n({data:e}),e)).catch(e=>{throw n({loading:!1,error:e}),e}).finally(()=>{n({loading:!1})}):(n({loading:!1,data:r}),r)}return o.apply(this,e)},r}}function A(e){return(t,n)=>{let r=e;void 0===r&&(r=String(n)).endsWith("$")&&(r=r.substring(0,r.length-1)),D().collectPropsField({name:n,prop:r,target:t.constructor,observable:!0})}}function K(){return(e,t,n)=>(void 0===n&&(n=Object.getOwnPropertyDescriptor(e,t)),D().collectPostProvided({name:t,target:e.constructor,descriptor:n}),n)}function U(e){return(t,n)=>{D().collectPropsField({name:n,prop:e||String(n),target:t.constructor,observable:!1})}}function q(){return(e,t)=>{D().collectStatedField({name:t,target:e.constructor})}}function z(e){return t=>{const n="object"==typeof e?e.name:e,r="object"==typeof e&&e.singleton;T(t),Object.defineProperty(t,l,{writable:!1,value:!0}),D().collectStatedBean({name:n,target:t,singleton:r})}}function G(e,o){const i=p(),a=t(i),[,c]=n(0);let u,d;void 0!==o&&("object"==typeof o?(u=o.name,d=o.props):"string"!=typeof o&&"symbol"!=typeof o||(u=o));const h=s(e=>{c(e=>e+1)},[]),l=a.container;if(void 0===l)throw new Error("not found stated bean container.");const[b]=n(()=>{let t;if(y(e)&&!g(e)){const n=e;t={type:n.constructor,factory:n,name:u,props:d}}else t={type:e,name:u,props:d};return l.register(new k(t))}),[f]=n(()=>b.state$.subscribe(h));return r(()=>{b.props$.next(d)},[d,b]),r(()=>()=>f.unsubscribe(),[f]),b.proxy}function H(e){const o=p(),i=t(o),[,a]=n(0),c="object"==typeof e?e.type:e,{name:u,observedFields:d}="object"==typeof e?e:{},h=s(e=>{(null==d||0===d.length||d.includes(e.fieldMeta.name))&&a(e=>e+1)},[d]),l=i.container;if(void 0===l)throw new Error("not found container");const[b]=n(()=>{let e;if(void 0!==u)e=l.getNamedObserver(u);else if(void 0!==c){const t=l.getTypedObserver(c);if(void 0!==t){if(!(t.length<=1))throw new Error(`Multiple bean [${c.name}] found.`);e=t[0]}}return e});if(void 0===b)throw new Error("bean observer is undefined.");const[f]=n(()=>b.state$.subscribe(h));return r(()=>()=>{f.unsubscribe()},[f]),b.proxy}function I(e){const[t,s]=n(()=>e instanceof a?e.getValue():null),[o,c]=n(e);return r(()=>{y(e)||c(e)},[e]),r(()=>{let e;return o instanceof i&&(e=o.subscribe(s)),()=>{e&&e.unsubscribe()}},[o]),t}function J(e,o){const i=p();if(void 0===t(i).container)throw new Error("not found container");const[a,c]=n(()=>({loading:!1,error:null,data:null,effect:o})),u=s(e=>{e.effect===o&&c(e)},[o]),[d]=n(()=>{const t=v(e);if(void 0===t)throw new Error("bean observer is undefined");return t.beanObserver.effect$.subscribe(u)});return r(()=>()=>{d.unsubscribe()},[d]),a}export{K as AfterProvided,k as BeanDefinition,x as BeanObserver,B as BeanWrapper,d as DefaultBeanFactory,V as Effect,f as ForceUpdate,A as ObservableProps,U as Props,q as Stated,z as StatedBean,h as StatedBeanApplication,l as StatedBeanClass,u as StatedBeanConsumer,$ as StatedBeanContainer,C as StatedBeanProvider,b as StatedBeanWrapper,R as UN_NAMED_BEAN,T as boundClass,S as boundMethod,v as getBeanWrapper,m as getPropertiesWithoutFunction,O as getProperty,p as getStatedBeanContext,P as isBeanContainerAware,M as isDisposableBean,y as isFunction,F as isInitializingBean,_ as isPromise,g as isStatedBeanClass,G as useBean,W as useContainer,H as useInject,I as useObservable,J as useObserveEffect};

@@ -49,3 +49,2 @@ import React, { useContext, useState, useEffect, useCallback } from 'react';

this._beanFactory = new DefaultBeanFactory();
this._debug = false;
}

@@ -59,8 +58,2 @@ StatedBeanApplication.prototype.getBeanFactory = function () {

};
StatedBeanApplication.prototype.setDebug = function (_debug) {
this._debug = _debug;
};
StatedBeanApplication.prototype.isDebug = function () {
return this._debug;
};
return StatedBeanApplication;

@@ -764,3 +757,4 @@ }());

}
return container.register(new BeanDefinition(beanProvider));
// Subscribing to the bean makes it not destroyed
container.register(new BeanDefinition(beanProvider)).state$.subscribe();
});

@@ -812,3 +806,3 @@ return container;

};
emitEffectAction_1({ loading: true, data: null, error: null });
emitEffectAction_1({ loading: true, error: null });
var result = originalMethod.apply(this, args);

@@ -818,12 +812,15 @@ if (isPromise(result)) {

.then(function (data) {
emitEffectAction_1({ loading: false, data: data, error: null });
emitEffectAction_1({ data: data });
return data;
})
.catch(function (e) {
emitEffectAction_1({ loading: false, data: null, error: e });
emitEffectAction_1({ loading: false, error: e });
throw e;
})
.finally(function () {
emitEffectAction_1({ loading: false });
});
}
else {
emitEffectAction_1({ loading: false, data: result, error: null });
emitEffectAction_1({ loading: false, data: result });
}

@@ -956,5 +953,2 @@ return result;

}
else {
throw new Error('invalid UseBeanOptions');
}
}

@@ -1011,6 +1005,5 @@ var beanChangeListener = useCallback(function (_action) {

var beanChangeListener = useCallback(function (action) {
var field = action.fieldMeta.name;
if (observedFields == null ||
observedFields.length === 0 ||
observedFields.includes(field)) {
observedFields.includes(action.fieldMeta.name)) {
setVersion(function (prev) { return prev + 1; });

@@ -1017,0 +1010,0 @@ }

@@ -1,1 +0,1 @@

import e,{useContext as t,useState as n,useEffect as r,useCallback as o}from"react";import{Subject as i,Observable as a,BehaviorSubject as s}from"rxjs";import{__extends as u,__assign as c}from"tslib";var p;function f(){return p||(p=e.createContext({})),p}var b=function(t){var n=t.children,r=f();return e.createElement(r.Consumer,null,(function(e){return n(e)}))},l=function(){function e(){}return e.prototype.createBean=function(e){return e.isFactoryBean?e.getFactory()(e.props):new e.beanType(e.props)},e.prototype.destroyBean=function(){},e}(),d=function(){function e(){this._beanFactory=new l,this._debug=!1}return e.prototype.getBeanFactory=function(){return this._beanFactory},e.prototype.setBeanFactory=function(e){return this._beanFactory=e,this},e.prototype.setDebug=function(e){this._debug=e},e.prototype.isDebug=function(){return this._debug},e}(),y=Symbol("stated-bean-class"),h=Symbol("stated-bean-wrapper"),v=Symbol("stated-bean-force-update");function g(e){return"function"==typeof e}function m(e){return Object.hasOwnProperty.call(e,y)}function _(e){if(Object.hasOwnProperty.call(e,h))return Reflect.get(e,h)}function O(e){return!!e&&"function"==typeof e.then}function P(e){if(e)return Object.keys(e).filter((function(t){return"function"!=typeof e[t]}))}var w=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t._counter$=new i,t}return u(t,e),t.prototype._subscribe=function(t){var n=this,r=new a((function(t){var r=e.prototype._subscribe.call(n,t);return function(){r.unsubscribe(),n._counter$.next(n.observers.length)}})).subscribe(t);return this._counter$.next(this.observers.length),r},t.prototype.subscribeCount=function(e){this._counter$.subscribe(e)},t.prototype.complete=function(){e.prototype.complete.call(this),this._counter$.complete()},t}(i),B=function(){function e(e){this._beanObserver=e,this.state$=new w}return Object.defineProperty(e.prototype,"beanObserver",{get:function(){return this._beanObserver},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"beanDefinition",{get:function(){return this.beanObserver.beanDefinition},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"beanMeta",{get:function(){return this.beanDefinition.beanMeta},enumerable:!0,configurable:!0}),e.prototype.forceUpdate=function(e){var t=(this.beanMeta.statedFields||[]).find((function(t){return t.name===e}));void 0!==t&&this.beanObserver.publishStateAction(t,this.beanObserver.proxy[e])},e}();function j(e,t){if(t in e)return e[t]}function F(e){var t=j(e,"afterProvided");return void 0!==t&&"function"==typeof t}function M(e){var t=j(e,"destroy");return void 0!==t&&"function"==typeof t}function x(e){var t=j(e,"setBeanContainer");return void 0!==t&&"function"==typeof t}var $=function(){function e(e,t,n){this._bean=e,this._container=t,this._beanDefinition=n,this.state$=new w,this.effect$=new i,this.props$=new i,this._proxyBean=new Proxy(this.origin,{});var r=this._observe();this._stateSubscription=r.state$.subscribe(this.state$),x(this.proxy)&&this.proxy.setBeanContainer(this._container)}return Object.defineProperty(e.prototype,"beanDefinition",{get:function(){return this._beanDefinition},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"proxy",{get:function(){return this._proxyBean},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"origin",{get:function(){return this._bean},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"beanMeta",{get:function(){return this.beanDefinition.beanMeta},enumerable:!0,configurable:!0}),e.prototype.destroy=function(){this.state$.complete(),this.effect$.complete(),M(this.proxy)&&this.proxy.destroy(),void 0!==this._stateSubscription&&this._stateSubscription.unsubscribe()},e.prototype.publishStateAction=function(e,t){var n={bean:this.proxy,nextValue:t,prevValue:this.proxy[e.name],fieldMeta:e};this.state$.next(n)},e.prototype._observe=function(){var e=this,t=this._defineStatedBean(this.proxy),n=this.beanMeta.propsFields;return void 0!==n&&(n.forEach((function(t){e._initPropsField(e.proxy,t,e.beanDefinition.props)})),this.props$.subscribe((function(t){n.forEach((function(n){e._updatePropsField(e.proxy,n,t)}))}))),setTimeout((function(){null!=e.beanMeta.postMethod&&void 0!==e.beanMeta.postMethod.descriptor?e.beanMeta.postMethod.descriptor.value.apply(e.proxy):F(e.proxy)&&e.proxy.afterProvided()}),0),t},e.prototype._defineStatedBean=function(e){var t=this,n=_(e);void 0===n&&(n=new B(this),Object.defineProperty(e,h,{value:n}),(this.beanMeta.statedFields||[]).forEach((function(r){t._observeBeanField(n,e,r)})));return n},e.prototype._observeBeanField=function(e,t,n){var r=Symbol(n.name.toString()+"_v");Object.defineProperty(t,r,{writable:!0,value:t[n.name]}),Object.defineProperty(t,n.name.toString(),{set:function(o){t[r]=o;var i={bean:t,nextValue:o,prevValue:t[n.name],fieldMeta:n};e.state$.next(i)},get:function(){return t[r]}})},e.prototype._initPropsField=function(e,t,n){var r=void 0===n?void 0:n[t.prop];t.observable?Reflect.set(e,t.name,new s(r)):Reflect.set(e,t.name,r)},e.prototype._updatePropsField=function(e,t,n){var r=void 0===n?void 0:n[t.prop],o=Reflect.get(e,t.name);if(t.observable){var i=o;Object.is(i.getValue(),r)||i.next(r)}else Object.is(o,r)||Reflect.set(e,t.name,r)},e}(),S=function(){function e(e){this._container=e,this._typedBeans=new WeakMap,this._namedBeans=new Map}return Object.defineProperty(e.prototype,"beanFactory",{get:function(){return this._container.application.getBeanFactory()},enumerable:!0,configurable:!0}),e.prototype.getTypedBean=function(e){return this._typedBeans.get(e)},e.prototype.getNamedBean=function(e){return this._namedBeans.get(e)},e.prototype.register=function(e){if(e.isNamedBean)return this.registerNamedBean(e);var t=this.createBeanObserver(e);return this._addTypedBean(e.beanType,t),t},e.prototype.registerNamedBean=function(e){var t=this.getNamedBean(e.beanName);if(void 0!==t)return t;var n=this.createBeanObserver(e);return this._namedBeans.set(e.beanName,n),this._addTypedBean(e.beanType,n),n},e.prototype.createBeanObserver=function(e){var t=this,n=this.beanFactory.createBean(e);e.setTarget(n);var r=new $(n,this._container,e);r.state$.subscribeCount((function(e){0===e&&(t.remove(r),r.destroy())}));var o=_(n);return void 0!==o&&o.state$.subscribeCount((function(r){0===r&&(t.beanFactory.destroyBean(e,n),o.state$.complete())})),r},e.prototype.remove=function(e){var t=e.beanDefinition;this._namedBeans.delete(t.beanName);var n=this._typedBeans.get(t.beanType);if(void 0!==n){var r=n.indexOf(e);n.splice(r,1)}},e.prototype._addTypedBean=function(e,t){var n=this._typedBeans.get(e);void 0===n?this._typedBeans.set(e,[t]):n.unshift(t)},e}(),T=function(){function e(e,t){this._parent=e,null!=t?this._app=t:null!=this._parent&&null!=this._parent.application?this._app=this._parent.application:this._app=new d,this._registry=new S(this)}return e.prototype.destroy=function(){},e.prototype.getBeanRegistry=function(){return this._registry},e.prototype.getTypedObserver=function(e){var t=this.getBeanRegistry().getTypedBean(e);return null==t&&this.parent&&(t=this.parent.getTypedObserver(e)),t},e.prototype.getNamedObserver=function(e){var t=this.getBeanRegistry().getNamedBean(e);return null==t&&this.parent&&(t=this.parent.getNamedObserver(e)),t},e.prototype.register=function(e){return this.getBeanRegistry().register(e)},Object.defineProperty(e.prototype,"parent",{get:function(){return this._parent},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"application",{get:function(){return this._app},enumerable:!0,configurable:!0}),e}();function N(e,t,n){var r=n.value;if("function"!=typeof r)throw new TypeError("@boundMethod decorator can only be applied to methods not: "+typeof r);var o=!1;return{configurable:!0,get:function(){if(o||this===e.prototype||Object.hasOwnProperty.call(this,t)||"function"!=typeof r)return r;var n=r.bind(this);return o=!0,Object.defineProperty(this,t,{configurable:!0,get:function(){return n},set:function(e){r=e,delete this[t]}}),o=!1,n},set:function(e){r=e}}}function E(e){var t;return"undefined"!=typeof Reflect&&"function"==typeof Reflect.ownKeys?t=Reflect.ownKeys(e.prototype):(t=Object.getOwnPropertyNames(e.prototype),"function"==typeof Object.getOwnPropertySymbols&&(t=t.concat(Object.getOwnPropertySymbols(e.prototype)))),t.forEach((function(t){if("constructor"!==t){var n=Object.getOwnPropertyDescriptor(e.prototype,t);void 0!==n&&"function"==typeof n.value&&Object.defineProperty(e.prototype,t,N(e,t,n))}})),e}var D,R=function(){function e(){this._beans=new WeakMap,this._statedFields=new WeakMap,this._propsFields=new WeakMap,this._postMethod=new WeakMap}return e.prototype.collectStatedBean=function(e){var t=e.target,n=this._statedFields.get(t);e.statedFields=n,e.propsFields=this._propsFields.get(t),e.postMethod=this._postMethod.get(t),this._beans.set(t,e),this._statedFields.delete(t),this._propsFields.delete(t),this._postMethod.delete(t)},e.prototype.collectStatedField=function(e){var t=e.target,n=this._statedFields.get(t);n?n.push(e):this._statedFields.set(t,[e])},e.prototype.collectPropsField=function(e){var t=e.target,n=this._propsFields.get(t);n?n.push(e):this._propsFields.set(t,[e])},e.prototype.collectPostProvided=function(e){this._postMethod.set(e.target,e)},e.prototype.getBeanMeta=function(e){return this._beans.get(e)},e.prototype.clear=function(){this._beans=new WeakMap,this._statedFields=new WeakMap,this._propsFields=new WeakMap,this._postMethod=new WeakMap},e}(),k=function(){return D||(D=new R)},W=Symbol("UN_NAMED_BEAN"),C=function(){function e(e){this._beanProvider=e}return e.prototype.getFactory=function(){return this._beanProvider.factory},e.prototype.getFactoryBeanType=function(){return void 0!==this.target?this.target.constructor:this.beanType},e.prototype.setTarget=function(e){this._target=e,this.isPlainObject&&Object.keys(e).forEach((function(t){"function"==typeof e[t]&&Object.defineProperty(e,t,{value:e[t].bind(e)})}))},Object.defineProperty(e.prototype,"target",{get:function(){return this._target},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"beanType",{get:function(){return this._beanProvider.type},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isSingleton",{get:function(){return!!(this._beanProvider.singleton||this.beanMeta&&this.beanMeta.singleton)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"beanName",{get:function(){var e=this._beanProvider.name||this.beanMeta.name;return this.isSingleton?e||this.beanType.name:e||W},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"beanMeta",{get:function(){var e=k(),t=this.isFactoryBean?this.getFactoryBeanType():this.beanType,n=e.getBeanMeta(t);return void 0===n?{target:t,name:this._beanProvider.name,statedFields:(P(this.target)||[]).map((function(e){return{name:e,target:t}}))}:n},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isNamedBean",{get:function(){return this.beanName!==W},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isFactoryBean",{get:function(){return g(this._beanProvider.factory)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isPlainObject",{get:function(){return this.isFactoryBean?"Object"===this.getFactoryBeanType().name:"Object"===this.beanType.name},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"props",{get:function(){return this._beanProvider.props},enumerable:!0,configurable:!0}),e}();function V(e){var o=e.providers,i=e.application,a=f(),s=t(a),u=n((function(){var e=new T(s.container,i);return(o||[]).forEach((function(t){var n;return n=g(t)?m(t)?{type:t}:{type:t.constructor,factory:t}:t,e.register(new C(n))})),e}))[0];return r((function(){return function(){u.destroy()}}),[u]),u}var A=function(t){var n=t.providers,r=t.application,o=t.children,i=f(),a=V({providers:n,application:r});return e.createElement(i.Provider,{value:{container:a}},o)};function U(e){return function(t,n,r){void 0===r&&(r=Object.getOwnPropertyDescriptor(t,n));var o=e||n,i=r.value;return r.value=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=_(this);if(void 0!==n){var r=function(e){var t=n.beanObserver;void 0!==t&&t.effect$.next(c({effect:o},e))};r({loading:!0,data:null,error:null});var a=i.apply(this,e);return O(a)?a.then((function(e){return r({loading:!1,data:e,error:null}),e})).catch((function(e){throw r({loading:!1,data:null,error:e}),e})):(r({loading:!1,data:a,error:null}),a)}return i.apply(this,e)},r}}function K(e){return function(t,n){var r=e;void 0===r&&(r=String(n)).endsWith("$")&&(r=r.substring(0,r.length-1)),k().collectPropsField({name:n,prop:r,target:t.constructor,observable:!0})}}function q(){return function(e,t,n){return void 0===n&&(n=Object.getOwnPropertyDescriptor(e,t)),k().collectPostProvided({name:t,target:e.constructor,descriptor:n}),n}}function z(e){return function(t,n){k().collectPropsField({name:n,prop:e||String(n),target:t.constructor,observable:!1})}}function G(){return function(e,t){k().collectStatedField({name:t,target:e.constructor})}}function H(e){return function(t){var n="object"==typeof e?e.name:e,r="object"==typeof e&&e.singleton;E(t),Object.defineProperty(t,y,{writable:!1,value:!0}),k().collectStatedBean({name:n,target:t,singleton:r})}}function I(e,i){var a,s,u=f(),c=t(u),p=n(0)[1];if(void 0!==i)if("object"==typeof i)a=i.name,s=i.props;else{if("string"!=typeof i&&"symbol"!=typeof i)throw new Error("invalid UseBeanOptions");a=i}var b=o((function(e){p((function(e){return e+1}))}),[]),l=c.container;if(void 0===l)throw new Error("not found stated bean container.");var d=n((function(){var t;if(g(e)&&!m(e)){var n=e;t={type:n.constructor,factory:n,name:a,props:s}}else t={type:e,name:a,props:s};return l.register(new C(t))}))[0],y=n((function(){return d.state$.subscribe(b)}))[0];return r((function(){d.props$.next(s)}),[s,d]),r((function(){return function(){return y.unsubscribe()}}),[y]),d.proxy}function J(e){var i=f(),a=t(i),s=n(0)[1],u="object"==typeof e?e.type:e,c="object"==typeof e?e:{},p=c.name,b=c.observedFields,l=o((function(e){var t=e.fieldMeta.name;(null==b||0===b.length||b.includes(t))&&s((function(e){return e+1}))}),[b]),d=a.container;if(void 0===d)throw new Error("not found container");var y=n((function(){var e;if(void 0!==p)e=d.getNamedObserver(p);else if(void 0!==u){var t=d.getTypedObserver(u);if(void 0!==t){if(!(t.length<=1))throw new Error("Multiple bean ["+u.name+"] found.");e=t[0]}}return e}))[0];if(void 0===y)throw new Error("bean observer is undefined.");var h=n((function(){return y.state$.subscribe(l)}))[0];return r((function(){return function(){h.unsubscribe()}}),[h]),y.proxy}function L(e){var t=n((function(){return e instanceof s?e.getValue():null})),o=t[0],i=t[1],u=n(e),c=u[0],p=u[1];return r((function(){g(e)||p(e)}),[e]),r((function(){var e;return c instanceof a&&(e=c.subscribe(i)),function(){e&&e.unsubscribe()}}),[c]),o}function Q(e,i){var a=f();if(void 0===t(a).container)throw new Error("not found container");var s=n((function(){return{loading:!1,error:null,data:null,effect:i}})),u=s[0],c=s[1],p=o((function(e){e.effect===i&&c(e)}),[i]),b=n((function(){var t=_(e);if(void 0===t)throw new Error("bean observer is undefined");return t.beanObserver.effect$.subscribe(p)}))[0];return r((function(){return function(){b.unsubscribe()}}),[b]),u}export{q as AfterProvided,C as BeanDefinition,$ as BeanObserver,B as BeanWrapper,l as DefaultBeanFactory,U as Effect,v as ForceUpdate,K as ObservableProps,z as Props,G as Stated,H as StatedBean,d as StatedBeanApplication,y as StatedBeanClass,b as StatedBeanConsumer,T as StatedBeanContainer,A as StatedBeanProvider,h as StatedBeanWrapper,W as UN_NAMED_BEAN,E as boundClass,N as boundMethod,_ as getBeanWrapper,P as getPropertiesWithoutFunction,j as getProperty,f as getStatedBeanContext,x as isBeanContainerAware,M as isDisposableBean,g as isFunction,F as isInitializingBean,O as isPromise,m as isStatedBeanClass,I as useBean,V as useContainer,J as useInject,L as useObservable,Q as useObserveEffect};
import e,{useContext as t,useState as n,useEffect as r,useCallback as o}from"react";import{Subject as i,Observable as a,BehaviorSubject as s}from"rxjs";import{__extends as u,__assign as c}from"tslib";var p;function f(){return p||(p=e.createContext({})),p}var b=function(t){var n=t.children,r=f();return e.createElement(r.Consumer,null,(function(e){return n(e)}))},d=function(){function e(){}return e.prototype.createBean=function(e){return e.isFactoryBean?e.getFactory()(e.props):new e.beanType(e.props)},e.prototype.destroyBean=function(){},e}(),l=function(){function e(){this._beanFactory=new d}return e.prototype.getBeanFactory=function(){return this._beanFactory},e.prototype.setBeanFactory=function(e){return this._beanFactory=e,this},e}(),y=Symbol("stated-bean-class"),h=Symbol("stated-bean-wrapper"),v=Symbol("stated-bean-force-update");function g(e){return"function"==typeof e}function m(e){return Object.hasOwnProperty.call(e,y)}function _(e){if(Object.hasOwnProperty.call(e,h))return Reflect.get(e,h)}function O(e){return!!e&&"function"==typeof e.then}function P(e){if(e)return Object.keys(e).filter((function(t){return"function"!=typeof e[t]}))}var w=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t._counter$=new i,t}return u(t,e),t.prototype._subscribe=function(t){var n=this,r=new a((function(t){var r=e.prototype._subscribe.call(n,t);return function(){r.unsubscribe(),n._counter$.next(n.observers.length)}})).subscribe(t);return this._counter$.next(this.observers.length),r},t.prototype.subscribeCount=function(e){this._counter$.subscribe(e)},t.prototype.complete=function(){e.prototype.complete.call(this),this._counter$.complete()},t}(i),B=function(){function e(e){this._beanObserver=e,this.state$=new w}return Object.defineProperty(e.prototype,"beanObserver",{get:function(){return this._beanObserver},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"beanDefinition",{get:function(){return this.beanObserver.beanDefinition},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"beanMeta",{get:function(){return this.beanDefinition.beanMeta},enumerable:!0,configurable:!0}),e.prototype.forceUpdate=function(e){var t=(this.beanMeta.statedFields||[]).find((function(t){return t.name===e}));void 0!==t&&this.beanObserver.publishStateAction(t,this.beanObserver.proxy[e])},e}();function j(e,t){if(t in e)return e[t]}function F(e){var t=j(e,"afterProvided");return void 0!==t&&"function"==typeof t}function M(e){var t=j(e,"destroy");return void 0!==t&&"function"==typeof t}function x(e){var t=j(e,"setBeanContainer");return void 0!==t&&"function"==typeof t}var $=function(){function e(e,t,n){this._bean=e,this._container=t,this._beanDefinition=n,this.state$=new w,this.effect$=new i,this.props$=new i,this._proxyBean=new Proxy(this.origin,{});var r=this._observe();this._stateSubscription=r.state$.subscribe(this.state$),x(this.proxy)&&this.proxy.setBeanContainer(this._container)}return Object.defineProperty(e.prototype,"beanDefinition",{get:function(){return this._beanDefinition},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"proxy",{get:function(){return this._proxyBean},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"origin",{get:function(){return this._bean},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"beanMeta",{get:function(){return this.beanDefinition.beanMeta},enumerable:!0,configurable:!0}),e.prototype.destroy=function(){this.state$.complete(),this.effect$.complete(),M(this.proxy)&&this.proxy.destroy(),void 0!==this._stateSubscription&&this._stateSubscription.unsubscribe()},e.prototype.publishStateAction=function(e,t){var n={bean:this.proxy,nextValue:t,prevValue:this.proxy[e.name],fieldMeta:e};this.state$.next(n)},e.prototype._observe=function(){var e=this,t=this._defineStatedBean(this.proxy),n=this.beanMeta.propsFields;return void 0!==n&&(n.forEach((function(t){e._initPropsField(e.proxy,t,e.beanDefinition.props)})),this.props$.subscribe((function(t){n.forEach((function(n){e._updatePropsField(e.proxy,n,t)}))}))),setTimeout((function(){null!=e.beanMeta.postMethod&&void 0!==e.beanMeta.postMethod.descriptor?e.beanMeta.postMethod.descriptor.value.apply(e.proxy):F(e.proxy)&&e.proxy.afterProvided()}),0),t},e.prototype._defineStatedBean=function(e){var t=this,n=_(e);void 0===n&&(n=new B(this),Object.defineProperty(e,h,{value:n}),(this.beanMeta.statedFields||[]).forEach((function(r){t._observeBeanField(n,e,r)})));return n},e.prototype._observeBeanField=function(e,t,n){var r=Symbol(n.name.toString()+"_v");Object.defineProperty(t,r,{writable:!0,value:t[n.name]}),Object.defineProperty(t,n.name.toString(),{set:function(o){t[r]=o;var i={bean:t,nextValue:o,prevValue:t[n.name],fieldMeta:n};e.state$.next(i)},get:function(){return t[r]}})},e.prototype._initPropsField=function(e,t,n){var r=void 0===n?void 0:n[t.prop];t.observable?Reflect.set(e,t.name,new s(r)):Reflect.set(e,t.name,r)},e.prototype._updatePropsField=function(e,t,n){var r=void 0===n?void 0:n[t.prop],o=Reflect.get(e,t.name);if(t.observable){var i=o;Object.is(i.getValue(),r)||i.next(r)}else Object.is(o,r)||Reflect.set(e,t.name,r)},e}(),S=function(){function e(e){this._container=e,this._typedBeans=new WeakMap,this._namedBeans=new Map}return Object.defineProperty(e.prototype,"beanFactory",{get:function(){return this._container.application.getBeanFactory()},enumerable:!0,configurable:!0}),e.prototype.getTypedBean=function(e){return this._typedBeans.get(e)},e.prototype.getNamedBean=function(e){return this._namedBeans.get(e)},e.prototype.register=function(e){if(e.isNamedBean)return this.registerNamedBean(e);var t=this.createBeanObserver(e);return this._addTypedBean(e.beanType,t),t},e.prototype.registerNamedBean=function(e){var t=this.getNamedBean(e.beanName);if(void 0!==t)return t;var n=this.createBeanObserver(e);return this._namedBeans.set(e.beanName,n),this._addTypedBean(e.beanType,n),n},e.prototype.createBeanObserver=function(e){var t=this,n=this.beanFactory.createBean(e);e.setTarget(n);var r=new $(n,this._container,e);r.state$.subscribeCount((function(e){0===e&&(t.remove(r),r.destroy())}));var o=_(n);return void 0!==o&&o.state$.subscribeCount((function(r){0===r&&(t.beanFactory.destroyBean(e,n),o.state$.complete())})),r},e.prototype.remove=function(e){var t=e.beanDefinition;this._namedBeans.delete(t.beanName);var n=this._typedBeans.get(t.beanType);if(void 0!==n){var r=n.indexOf(e);n.splice(r,1)}},e.prototype._addTypedBean=function(e,t){var n=this._typedBeans.get(e);void 0===n?this._typedBeans.set(e,[t]):n.unshift(t)},e}(),T=function(){function e(e,t){this._parent=e,null!=t?this._app=t:null!=this._parent&&null!=this._parent.application?this._app=this._parent.application:this._app=new l,this._registry=new S(this)}return e.prototype.destroy=function(){},e.prototype.getBeanRegistry=function(){return this._registry},e.prototype.getTypedObserver=function(e){var t=this.getBeanRegistry().getTypedBean(e);return null==t&&this.parent&&(t=this.parent.getTypedObserver(e)),t},e.prototype.getNamedObserver=function(e){var t=this.getBeanRegistry().getNamedBean(e);return null==t&&this.parent&&(t=this.parent.getNamedObserver(e)),t},e.prototype.register=function(e){return this.getBeanRegistry().register(e)},Object.defineProperty(e.prototype,"parent",{get:function(){return this._parent},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"application",{get:function(){return this._app},enumerable:!0,configurable:!0}),e}();function N(e,t,n){var r=n.value;if("function"!=typeof r)throw new TypeError("@boundMethod decorator can only be applied to methods not: "+typeof r);var o=!1;return{configurable:!0,get:function(){if(o||this===e.prototype||Object.hasOwnProperty.call(this,t)||"function"!=typeof r)return r;var n=r.bind(this);return o=!0,Object.defineProperty(this,t,{configurable:!0,get:function(){return n},set:function(e){r=e,delete this[t]}}),o=!1,n},set:function(e){r=e}}}function E(e){var t;return"undefined"!=typeof Reflect&&"function"==typeof Reflect.ownKeys?t=Reflect.ownKeys(e.prototype):(t=Object.getOwnPropertyNames(e.prototype),"function"==typeof Object.getOwnPropertySymbols&&(t=t.concat(Object.getOwnPropertySymbols(e.prototype)))),t.forEach((function(t){if("constructor"!==t){var n=Object.getOwnPropertyDescriptor(e.prototype,t);void 0!==n&&"function"==typeof n.value&&Object.defineProperty(e.prototype,t,N(e,t,n))}})),e}var D,R=function(){function e(){this._beans=new WeakMap,this._statedFields=new WeakMap,this._propsFields=new WeakMap,this._postMethod=new WeakMap}return e.prototype.collectStatedBean=function(e){var t=e.target,n=this._statedFields.get(t);e.statedFields=n,e.propsFields=this._propsFields.get(t),e.postMethod=this._postMethod.get(t),this._beans.set(t,e),this._statedFields.delete(t),this._propsFields.delete(t),this._postMethod.delete(t)},e.prototype.collectStatedField=function(e){var t=e.target,n=this._statedFields.get(t);n?n.push(e):this._statedFields.set(t,[e])},e.prototype.collectPropsField=function(e){var t=e.target,n=this._propsFields.get(t);n?n.push(e):this._propsFields.set(t,[e])},e.prototype.collectPostProvided=function(e){this._postMethod.set(e.target,e)},e.prototype.getBeanMeta=function(e){return this._beans.get(e)},e.prototype.clear=function(){this._beans=new WeakMap,this._statedFields=new WeakMap,this._propsFields=new WeakMap,this._postMethod=new WeakMap},e}(),k=function(){return D||(D=new R)},W=Symbol("UN_NAMED_BEAN"),C=function(){function e(e){this._beanProvider=e}return e.prototype.getFactory=function(){return this._beanProvider.factory},e.prototype.getFactoryBeanType=function(){return void 0!==this.target?this.target.constructor:this.beanType},e.prototype.setTarget=function(e){this._target=e,this.isPlainObject&&Object.keys(e).forEach((function(t){"function"==typeof e[t]&&Object.defineProperty(e,t,{value:e[t].bind(e)})}))},Object.defineProperty(e.prototype,"target",{get:function(){return this._target},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"beanType",{get:function(){return this._beanProvider.type},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isSingleton",{get:function(){return!!(this._beanProvider.singleton||this.beanMeta&&this.beanMeta.singleton)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"beanName",{get:function(){var e=this._beanProvider.name||this.beanMeta.name;return this.isSingleton?e||this.beanType.name:e||W},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"beanMeta",{get:function(){var e=k(),t=this.isFactoryBean?this.getFactoryBeanType():this.beanType,n=e.getBeanMeta(t);return void 0===n?{target:t,name:this._beanProvider.name,statedFields:(P(this.target)||[]).map((function(e){return{name:e,target:t}}))}:n},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isNamedBean",{get:function(){return this.beanName!==W},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isFactoryBean",{get:function(){return g(this._beanProvider.factory)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isPlainObject",{get:function(){return this.isFactoryBean?"Object"===this.getFactoryBeanType().name:"Object"===this.beanType.name},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"props",{get:function(){return this._beanProvider.props},enumerable:!0,configurable:!0}),e}();function V(e){var o=e.providers,i=e.application,a=f(),s=t(a),u=n((function(){var e=new T(s.container,i);return(o||[]).forEach((function(t){var n;n=g(t)?m(t)?{type:t}:{type:t.constructor,factory:t}:t,e.register(new C(n)).state$.subscribe()})),e}))[0];return r((function(){return function(){u.destroy()}}),[u]),u}var A=function(t){var n=t.providers,r=t.application,o=t.children,i=f(),a=V({providers:n,application:r});return e.createElement(i.Provider,{value:{container:a}},o)};function K(e){return function(t,n,r){void 0===r&&(r=Object.getOwnPropertyDescriptor(t,n));var o=e||n,i=r.value;return r.value=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=_(this);if(void 0!==n){var r=function(e){var t=n.beanObserver;void 0!==t&&t.effect$.next(c({effect:o},e))};r({loading:!0,error:null});var a=i.apply(this,e);return O(a)?a.then((function(e){return r({data:e}),e})).catch((function(e){throw r({loading:!1,error:e}),e})).finally((function(){r({loading:!1})})):(r({loading:!1,data:a}),a)}return i.apply(this,e)},r}}function U(e){return function(t,n){var r=e;void 0===r&&(r=String(n)).endsWith("$")&&(r=r.substring(0,r.length-1)),k().collectPropsField({name:n,prop:r,target:t.constructor,observable:!0})}}function q(){return function(e,t,n){return void 0===n&&(n=Object.getOwnPropertyDescriptor(e,t)),k().collectPostProvided({name:t,target:e.constructor,descriptor:n}),n}}function z(e){return function(t,n){k().collectPropsField({name:n,prop:e||String(n),target:t.constructor,observable:!1})}}function G(){return function(e,t){k().collectStatedField({name:t,target:e.constructor})}}function H(e){return function(t){var n="object"==typeof e?e.name:e,r="object"==typeof e&&e.singleton;E(t),Object.defineProperty(t,y,{writable:!1,value:!0}),k().collectStatedBean({name:n,target:t,singleton:r})}}function I(e,i){var a,s,u=f(),c=t(u),p=n(0)[1];void 0!==i&&("object"==typeof i?(a=i.name,s=i.props):"string"!=typeof i&&"symbol"!=typeof i||(a=i));var b=o((function(e){p((function(e){return e+1}))}),[]),d=c.container;if(void 0===d)throw new Error("not found stated bean container.");var l=n((function(){var t;if(g(e)&&!m(e)){var n=e;t={type:n.constructor,factory:n,name:a,props:s}}else t={type:e,name:a,props:s};return d.register(new C(t))}))[0],y=n((function(){return l.state$.subscribe(b)}))[0];return r((function(){l.props$.next(s)}),[s,l]),r((function(){return function(){return y.unsubscribe()}}),[y]),l.proxy}function J(e){var i=f(),a=t(i),s=n(0)[1],u="object"==typeof e?e.type:e,c="object"==typeof e?e:{},p=c.name,b=c.observedFields,d=o((function(e){(null==b||0===b.length||b.includes(e.fieldMeta.name))&&s((function(e){return e+1}))}),[b]),l=a.container;if(void 0===l)throw new Error("not found container");var y=n((function(){var e;if(void 0!==p)e=l.getNamedObserver(p);else if(void 0!==u){var t=l.getTypedObserver(u);if(void 0!==t){if(!(t.length<=1))throw new Error("Multiple bean ["+u.name+"] found.");e=t[0]}}return e}))[0];if(void 0===y)throw new Error("bean observer is undefined.");var h=n((function(){return y.state$.subscribe(d)}))[0];return r((function(){return function(){h.unsubscribe()}}),[h]),y.proxy}function L(e){var t=n((function(){return e instanceof s?e.getValue():null})),o=t[0],i=t[1],u=n(e),c=u[0],p=u[1];return r((function(){g(e)||p(e)}),[e]),r((function(){var e;return c instanceof a&&(e=c.subscribe(i)),function(){e&&e.unsubscribe()}}),[c]),o}function Q(e,i){var a=f();if(void 0===t(a).container)throw new Error("not found container");var s=n((function(){return{loading:!1,error:null,data:null,effect:i}})),u=s[0],c=s[1],p=o((function(e){e.effect===i&&c(e)}),[i]),b=n((function(){var t=_(e);if(void 0===t)throw new Error("bean observer is undefined");return t.beanObserver.effect$.subscribe(p)}))[0];return r((function(){return function(){b.unsubscribe()}}),[b]),u}export{q as AfterProvided,C as BeanDefinition,$ as BeanObserver,B as BeanWrapper,d as DefaultBeanFactory,K as Effect,v as ForceUpdate,U as ObservableProps,z as Props,G as Stated,H as StatedBean,l as StatedBeanApplication,y as StatedBeanClass,b as StatedBeanConsumer,T as StatedBeanContainer,A as StatedBeanProvider,h as StatedBeanWrapper,W as UN_NAMED_BEAN,E as boundClass,N as boundMethod,_ as getBeanWrapper,P as getPropertiesWithoutFunction,j as getProperty,f as getStatedBeanContext,x as isBeanContainerAware,M as isDisposableBean,g as isFunction,F as isInitializingBean,O as isPromise,m as isStatedBeanClass,I as useBean,V as useContainer,J as useInject,L as useObservable,Q as useObserveEffect};

@@ -9,8 +9,5 @@ import { IBeanFactory } from './StatedBeanFactory';

private _beanFactory;
private _debug;
getBeanFactory(): IBeanFactory;
setBeanFactory(beanFactory: IBeanFactory): this;
setDebug(_debug: boolean): void;
isDebug(): boolean;
}
//# sourceMappingURL=StatedBeanApplication.d.ts.map

@@ -10,4 +10,4 @@ import { StatedFieldMeta } from './StatedMetadata';

loading: boolean;
data: T;
error: unknown;
data: T;
effect: string | symbol;

@@ -14,0 +14,0 @@ }

@@ -53,3 +53,2 @@ (function (global, factory) {

this._beanFactory = new DefaultBeanFactory();
this._debug = false;
}

@@ -63,8 +62,2 @@ StatedBeanApplication.prototype.getBeanFactory = function () {

};
StatedBeanApplication.prototype.setDebug = function (_debug) {
this._debug = _debug;
};
StatedBeanApplication.prototype.isDebug = function () {
return this._debug;
};
return StatedBeanApplication;

@@ -768,3 +761,4 @@ }());

}
return container.register(new BeanDefinition(beanProvider));
// Subscribing to the bean makes it not destroyed
container.register(new BeanDefinition(beanProvider)).state$.subscribe();
});

@@ -816,3 +810,3 @@ return container;

};
emitEffectAction_1({ loading: true, data: null, error: null });
emitEffectAction_1({ loading: true, error: null });
var result = originalMethod.apply(this, args);

@@ -822,12 +816,15 @@ if (isPromise(result)) {

.then(function (data) {
emitEffectAction_1({ loading: false, data: data, error: null });
emitEffectAction_1({ data: data });
return data;
})
.catch(function (e) {
emitEffectAction_1({ loading: false, data: null, error: e });
emitEffectAction_1({ loading: false, error: e });
throw e;
})
.finally(function () {
emitEffectAction_1({ loading: false });
});
}
else {
emitEffectAction_1({ loading: false, data: result, error: null });
emitEffectAction_1({ loading: false, data: result });
}

@@ -960,5 +957,2 @@ return result;

}
else {
throw new Error('invalid UseBeanOptions');
}
}

@@ -1015,6 +1009,5 @@ var beanChangeListener = React.useCallback(function (_action) {

var beanChangeListener = React.useCallback(function (action) {
var field = action.fieldMeta.name;
if (observedFields == null ||
observedFields.length === 0 ||
observedFields.includes(field)) {
observedFields.includes(action.fieldMeta.name)) {
setVersion(function (prev) { return prev + 1; });

@@ -1021,0 +1014,0 @@ }

@@ -1,1 +0,1 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("rxjs"),require("tslib")):"function"==typeof define&&define.amd?define(["exports","react","rxjs","tslib"],t):t((e=e||self).StatedBean={},e.React,e.rxjs,e.tslib)}(this,(function(e,t,n,r){"use strict";var o,i="default"in t?t.default:t;function a(){return o||(o=i.createContext({})),o}var s=function(){function e(){}return e.prototype.createBean=function(e){return e.isFactoryBean?e.getFactory()(e.props):new e.beanType(e.props)},e.prototype.destroyBean=function(){},e}(),u=function(){function e(){this._beanFactory=new s,this._debug=!1}return e.prototype.getBeanFactory=function(){return this._beanFactory},e.prototype.setBeanFactory=function(e){return this._beanFactory=e,this},e.prototype.setDebug=function(e){this._debug=e},e.prototype.isDebug=function(){return this._debug},e}(),c=Symbol("stated-bean-class"),p=Symbol("stated-bean-wrapper"),f=Symbol("stated-bean-force-update");function b(e){return"function"==typeof e}function d(e){return Object.hasOwnProperty.call(e,c)}function l(e){if(Object.hasOwnProperty.call(e,p))return Reflect.get(e,p)}function y(e){return!!e&&"function"==typeof e.then}function h(e){if(e)return Object.keys(e).filter((function(t){return"function"!=typeof e[t]}))}var v=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t._counter$=new n.Subject,t}return r.__extends(t,e),t.prototype._subscribe=function(t){var r=this,o=new n.Observable((function(t){var n=e.prototype._subscribe.call(r,t);return function(){n.unsubscribe(),r._counter$.next(r.observers.length)}})).subscribe(t);return this._counter$.next(this.observers.length),o},t.prototype.subscribeCount=function(e){this._counter$.subscribe(e)},t.prototype.complete=function(){e.prototype.complete.call(this),this._counter$.complete()},t}(n.Subject),g=function(){function e(e){this._beanObserver=e,this.state$=new v}return Object.defineProperty(e.prototype,"beanObserver",{get:function(){return this._beanObserver},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"beanDefinition",{get:function(){return this.beanObserver.beanDefinition},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"beanMeta",{get:function(){return this.beanDefinition.beanMeta},enumerable:!0,configurable:!0}),e.prototype.forceUpdate=function(e){var t=(this.beanMeta.statedFields||[]).find((function(t){return t.name===e}));void 0!==t&&this.beanObserver.publishStateAction(t,this.beanObserver.proxy[e])},e}();function _(e,t){if(t in e)return e[t]}function m(e){var t=_(e,"afterProvided");return void 0!==t&&"function"==typeof t}function B(e){var t=_(e,"destroy");return void 0!==t&&"function"==typeof t}function O(e){var t=_(e,"setBeanContainer");return void 0!==t&&"function"==typeof t}var P=function(){function e(e,t,r){this._bean=e,this._container=t,this._beanDefinition=r,this.state$=new v,this.effect$=new n.Subject,this.props$=new n.Subject,this._proxyBean=new Proxy(this.origin,{});var o=this._observe();this._stateSubscription=o.state$.subscribe(this.state$),O(this.proxy)&&this.proxy.setBeanContainer(this._container)}return Object.defineProperty(e.prototype,"beanDefinition",{get:function(){return this._beanDefinition},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"proxy",{get:function(){return this._proxyBean},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"origin",{get:function(){return this._bean},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"beanMeta",{get:function(){return this.beanDefinition.beanMeta},enumerable:!0,configurable:!0}),e.prototype.destroy=function(){this.state$.complete(),this.effect$.complete(),B(this.proxy)&&this.proxy.destroy(),void 0!==this._stateSubscription&&this._stateSubscription.unsubscribe()},e.prototype.publishStateAction=function(e,t){var n={bean:this.proxy,nextValue:t,prevValue:this.proxy[e.name],fieldMeta:e};this.state$.next(n)},e.prototype._observe=function(){var e=this,t=this._defineStatedBean(this.proxy),n=this.beanMeta.propsFields;return void 0!==n&&(n.forEach((function(t){e._initPropsField(e.proxy,t,e.beanDefinition.props)})),this.props$.subscribe((function(t){n.forEach((function(n){e._updatePropsField(e.proxy,n,t)}))}))),setTimeout((function(){null!=e.beanMeta.postMethod&&void 0!==e.beanMeta.postMethod.descriptor?e.beanMeta.postMethod.descriptor.value.apply(e.proxy):m(e.proxy)&&e.proxy.afterProvided()}),0),t},e.prototype._defineStatedBean=function(e){var t=this,n=l(e);void 0===n&&(n=new g(this),Object.defineProperty(e,p,{value:n}),(this.beanMeta.statedFields||[]).forEach((function(r){t._observeBeanField(n,e,r)})));return n},e.prototype._observeBeanField=function(e,t,n){var r=Symbol(n.name.toString()+"_v");Object.defineProperty(t,r,{writable:!0,value:t[n.name]}),Object.defineProperty(t,n.name.toString(),{set:function(o){t[r]=o;var i={bean:t,nextValue:o,prevValue:t[n.name],fieldMeta:n};e.state$.next(i)},get:function(){return t[r]}})},e.prototype._initPropsField=function(e,t,r){var o=void 0===r?void 0:r[t.prop];t.observable?Reflect.set(e,t.name,new n.BehaviorSubject(o)):Reflect.set(e,t.name,o)},e.prototype._updatePropsField=function(e,t,n){var r=void 0===n?void 0:n[t.prop],o=Reflect.get(e,t.name);if(t.observable){var i=o;Object.is(i.getValue(),r)||i.next(r)}else Object.is(o,r)||Reflect.set(e,t.name,r)},e}(),j=function(){function e(e){this._container=e,this._typedBeans=new WeakMap,this._namedBeans=new Map}return Object.defineProperty(e.prototype,"beanFactory",{get:function(){return this._container.application.getBeanFactory()},enumerable:!0,configurable:!0}),e.prototype.getTypedBean=function(e){return this._typedBeans.get(e)},e.prototype.getNamedBean=function(e){return this._namedBeans.get(e)},e.prototype.register=function(e){if(e.isNamedBean)return this.registerNamedBean(e);var t=this.createBeanObserver(e);return this._addTypedBean(e.beanType,t),t},e.prototype.registerNamedBean=function(e){var t=this.getNamedBean(e.beanName);if(void 0!==t)return t;var n=this.createBeanObserver(e);return this._namedBeans.set(e.beanName,n),this._addTypedBean(e.beanType,n),n},e.prototype.createBeanObserver=function(e){var t=this,n=this.beanFactory.createBean(e);e.setTarget(n);var r=new P(n,this._container,e);r.state$.subscribeCount((function(e){0===e&&(t.remove(r),r.destroy())}));var o=l(n);return void 0!==o&&o.state$.subscribeCount((function(r){0===r&&(t.beanFactory.destroyBean(e,n),o.state$.complete())})),r},e.prototype.remove=function(e){var t=e.beanDefinition;this._namedBeans.delete(t.beanName);var n=this._typedBeans.get(t.beanType);if(void 0!==n){var r=n.indexOf(e);n.splice(r,1)}},e.prototype._addTypedBean=function(e,t){var n=this._typedBeans.get(e);void 0===n?this._typedBeans.set(e,[t]):n.unshift(t)},e}(),w=function(){function e(e,t){this._parent=e,null!=t?this._app=t:null!=this._parent&&null!=this._parent.application?this._app=this._parent.application:this._app=new u,this._registry=new j(this)}return e.prototype.destroy=function(){},e.prototype.getBeanRegistry=function(){return this._registry},e.prototype.getTypedObserver=function(e){var t=this.getBeanRegistry().getTypedBean(e);return null==t&&this.parent&&(t=this.parent.getTypedObserver(e)),t},e.prototype.getNamedObserver=function(e){var t=this.getBeanRegistry().getNamedBean(e);return null==t&&this.parent&&(t=this.parent.getNamedObserver(e)),t},e.prototype.register=function(e){return this.getBeanRegistry().register(e)},Object.defineProperty(e.prototype,"parent",{get:function(){return this._parent},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"application",{get:function(){return this._app},enumerable:!0,configurable:!0}),e}();function F(e,t,n){var r=n.value;if("function"!=typeof r)throw new TypeError("@boundMethod decorator can only be applied to methods not: "+typeof r);var o=!1;return{configurable:!0,get:function(){if(o||this===e.prototype||Object.hasOwnProperty.call(this,t)||"function"!=typeof r)return r;var n=r.bind(this);return o=!0,Object.defineProperty(this,t,{configurable:!0,get:function(){return n},set:function(e){r=e,delete this[t]}}),o=!1,n},set:function(e){r=e}}}function S(e){var t;return"undefined"!=typeof Reflect&&"function"==typeof Reflect.ownKeys?t=Reflect.ownKeys(e.prototype):(t=Object.getOwnPropertyNames(e.prototype),"function"==typeof Object.getOwnPropertySymbols&&(t=t.concat(Object.getOwnPropertySymbols(e.prototype)))),t.forEach((function(t){if("constructor"!==t){var n=Object.getOwnPropertyDescriptor(e.prototype,t);void 0!==n&&"function"==typeof n.value&&Object.defineProperty(e.prototype,t,F(e,t,n))}})),e}var M,x=function(){function e(){this._beans=new WeakMap,this._statedFields=new WeakMap,this._propsFields=new WeakMap,this._postMethod=new WeakMap}return e.prototype.collectStatedBean=function(e){var t=e.target,n=this._statedFields.get(t);e.statedFields=n,e.propsFields=this._propsFields.get(t),e.postMethod=this._postMethod.get(t),this._beans.set(t,e),this._statedFields.delete(t),this._propsFields.delete(t),this._postMethod.delete(t)},e.prototype.collectStatedField=function(e){var t=e.target,n=this._statedFields.get(t);n?n.push(e):this._statedFields.set(t,[e])},e.prototype.collectPropsField=function(e){var t=e.target,n=this._propsFields.get(t);n?n.push(e):this._propsFields.set(t,[e])},e.prototype.collectPostProvided=function(e){this._postMethod.set(e.target,e)},e.prototype.getBeanMeta=function(e){return this._beans.get(e)},e.prototype.clear=function(){this._beans=new WeakMap,this._statedFields=new WeakMap,this._propsFields=new WeakMap,this._postMethod=new WeakMap},e}(),E=function(){return M||(M=new x)},$=Symbol("UN_NAMED_BEAN"),T=function(){function e(e){this._beanProvider=e}return e.prototype.getFactory=function(){return this._beanProvider.factory},e.prototype.getFactoryBeanType=function(){return void 0!==this.target?this.target.constructor:this.beanType},e.prototype.setTarget=function(e){this._target=e,this.isPlainObject&&Object.keys(e).forEach((function(t){"function"==typeof e[t]&&Object.defineProperty(e,t,{value:e[t].bind(e)})}))},Object.defineProperty(e.prototype,"target",{get:function(){return this._target},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"beanType",{get:function(){return this._beanProvider.type},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isSingleton",{get:function(){return!!(this._beanProvider.singleton||this.beanMeta&&this.beanMeta.singleton)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"beanName",{get:function(){var e=this._beanProvider.name||this.beanMeta.name;return this.isSingleton?e||this.beanType.name:e||$},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"beanMeta",{get:function(){var e=E(),t=this.isFactoryBean?this.getFactoryBeanType():this.beanType,n=e.getBeanMeta(t);return void 0===n?{target:t,name:this._beanProvider.name,statedFields:(h(this.target)||[]).map((function(e){return{name:e,target:t}}))}:n},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isNamedBean",{get:function(){return this.beanName!==$},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isFactoryBean",{get:function(){return b(this._beanProvider.factory)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isPlainObject",{get:function(){return this.isFactoryBean?"Object"===this.getFactoryBeanType().name:"Object"===this.beanType.name},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"props",{get:function(){return this._beanProvider.props},enumerable:!0,configurable:!0}),e}();function C(e){var n=e.providers,r=e.application,o=a(),i=t.useContext(o),s=t.useState((function(){var e=new w(i.container,r);return(n||[]).forEach((function(t){var n;return n=b(t)?d(t)?{type:t}:{type:t.constructor,factory:t}:t,e.register(new T(n))})),e}))[0];return t.useEffect((function(){return function(){s.destroy()}}),[s]),s}e.AfterProvided=function(){return function(e,t,n){return void 0===n&&(n=Object.getOwnPropertyDescriptor(e,t)),E().collectPostProvided({name:t,target:e.constructor,descriptor:n}),n}},e.BeanDefinition=T,e.BeanObserver=P,e.BeanWrapper=g,e.DefaultBeanFactory=s,e.Effect=function(e){return function(t,n,o){void 0===o&&(o=Object.getOwnPropertyDescriptor(t,n));var i=e||n,a=o.value;return o.value=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=l(this);if(void 0!==n){var o=function(e){var t=n.beanObserver;void 0!==t&&t.effect$.next(r.__assign({effect:i},e))};o({loading:!0,data:null,error:null});var s=a.apply(this,e);return y(s)?s.then((function(e){return o({loading:!1,data:e,error:null}),e})).catch((function(e){throw o({loading:!1,data:null,error:e}),e})):(o({loading:!1,data:s,error:null}),s)}return a.apply(this,e)},o}},e.ForceUpdate=f,e.ObservableProps=function(e){return function(t,n){var r=e;void 0===r&&(r=String(n)).endsWith("$")&&(r=r.substring(0,r.length-1)),E().collectPropsField({name:n,prop:r,target:t.constructor,observable:!0})}},e.Props=function(e){return function(t,n){E().collectPropsField({name:n,prop:e||String(n),target:t.constructor,observable:!1})}},e.Stated=function(){return function(e,t){E().collectStatedField({name:t,target:e.constructor})}},e.StatedBean=function(e){return function(t){var n="object"==typeof e?e.name:e,r="object"==typeof e&&e.singleton;S(t),Object.defineProperty(t,c,{writable:!1,value:!0}),E().collectStatedBean({name:n,target:t,singleton:r})}},e.StatedBeanApplication=u,e.StatedBeanClass=c,e.StatedBeanConsumer=function(e){var t=e.children,n=a();return i.createElement(n.Consumer,null,(function(e){return t(e)}))},e.StatedBeanContainer=w,e.StatedBeanProvider=function(e){var t=e.providers,n=e.application,r=e.children,o=a(),s=C({providers:t,application:n});return i.createElement(o.Provider,{value:{container:s}},r)},e.StatedBeanWrapper=p,e.UN_NAMED_BEAN=$,e.boundClass=S,e.boundMethod=F,e.getBeanWrapper=l,e.getPropertiesWithoutFunction=h,e.getProperty=_,e.getStatedBeanContext=a,e.isBeanContainerAware=O,e.isDisposableBean=B,e.isFunction=b,e.isInitializingBean=m,e.isPromise=y,e.isStatedBeanClass=d,e.useBean=function(e,n){var r,o,i=a(),s=t.useContext(i),u=t.useState(0)[1];if(void 0!==n)if("object"==typeof n)r=n.name,o=n.props;else{if("string"!=typeof n&&"symbol"!=typeof n)throw new Error("invalid UseBeanOptions");r=n}var c=t.useCallback((function(e){u((function(e){return e+1}))}),[]),p=s.container;if(void 0===p)throw new Error("not found stated bean container.");var f=t.useState((function(){var t;if(b(e)&&!d(e)){var n=e;t={type:n.constructor,factory:n,name:r,props:o}}else t={type:e,name:r,props:o};return p.register(new T(t))}))[0],l=t.useState((function(){return f.state$.subscribe(c)}))[0];return t.useEffect((function(){f.props$.next(o)}),[o,f]),t.useEffect((function(){return function(){return l.unsubscribe()}}),[l]),f.proxy},e.useContainer=C,e.useInject=function(e){var n=a(),r=t.useContext(n),o=t.useState(0)[1],i="object"==typeof e?e.type:e,s="object"==typeof e?e:{},u=s.name,c=s.observedFields,p=t.useCallback((function(e){var t=e.fieldMeta.name;(null==c||0===c.length||c.includes(t))&&o((function(e){return e+1}))}),[c]),f=r.container;if(void 0===f)throw new Error("not found container");var b=t.useState((function(){var e;if(void 0!==u)e=f.getNamedObserver(u);else if(void 0!==i){var t=f.getTypedObserver(i);if(void 0!==t){if(!(t.length<=1))throw new Error("Multiple bean ["+i.name+"] found.");e=t[0]}}return e}))[0];if(void 0===b)throw new Error("bean observer is undefined.");var d=t.useState((function(){return b.state$.subscribe(p)}))[0];return t.useEffect((function(){return function(){d.unsubscribe()}}),[d]),b.proxy},e.useObservable=function(e){var r=t.useState((function(){return e instanceof n.BehaviorSubject?e.getValue():null})),o=r[0],i=r[1],a=t.useState(e),s=a[0],u=a[1];return t.useEffect((function(){b(e)||u(e)}),[e]),t.useEffect((function(){var e;return s instanceof n.Observable&&(e=s.subscribe(i)),function(){e&&e.unsubscribe()}}),[s]),o},e.useObserveEffect=function(e,n){var r=a();if(void 0===t.useContext(r).container)throw new Error("not found container");var o=t.useState((function(){return{loading:!1,error:null,data:null,effect:n}})),i=o[0],s=o[1],u=t.useCallback((function(e){e.effect===n&&s(e)}),[n]),c=t.useState((function(){var t=l(e);if(void 0===t)throw new Error("bean observer is undefined");return t.beanObserver.effect$.subscribe(u)}))[0];return t.useEffect((function(){return function(){c.unsubscribe()}}),[c]),i},Object.defineProperty(e,"__esModule",{value:!0})}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("rxjs"),require("tslib")):"function"==typeof define&&define.amd?define(["exports","react","rxjs","tslib"],t):t((e=e||self).StatedBean={},e.React,e.rxjs,e.tslib)}(this,(function(e,t,n,r){"use strict";var o,i="default"in t?t.default:t;function a(){return o||(o=i.createContext({})),o}var s=function(){function e(){}return e.prototype.createBean=function(e){return e.isFactoryBean?e.getFactory()(e.props):new e.beanType(e.props)},e.prototype.destroyBean=function(){},e}(),u=function(){function e(){this._beanFactory=new s}return e.prototype.getBeanFactory=function(){return this._beanFactory},e.prototype.setBeanFactory=function(e){return this._beanFactory=e,this},e}(),c=Symbol("stated-bean-class"),p=Symbol("stated-bean-wrapper"),f=Symbol("stated-bean-force-update");function b(e){return"function"==typeof e}function d(e){return Object.hasOwnProperty.call(e,c)}function l(e){if(Object.hasOwnProperty.call(e,p))return Reflect.get(e,p)}function y(e){return!!e&&"function"==typeof e.then}function h(e){if(e)return Object.keys(e).filter((function(t){return"function"!=typeof e[t]}))}var v=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t._counter$=new n.Subject,t}return r.__extends(t,e),t.prototype._subscribe=function(t){var r=this,o=new n.Observable((function(t){var n=e.prototype._subscribe.call(r,t);return function(){n.unsubscribe(),r._counter$.next(r.observers.length)}})).subscribe(t);return this._counter$.next(this.observers.length),o},t.prototype.subscribeCount=function(e){this._counter$.subscribe(e)},t.prototype.complete=function(){e.prototype.complete.call(this),this._counter$.complete()},t}(n.Subject),g=function(){function e(e){this._beanObserver=e,this.state$=new v}return Object.defineProperty(e.prototype,"beanObserver",{get:function(){return this._beanObserver},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"beanDefinition",{get:function(){return this.beanObserver.beanDefinition},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"beanMeta",{get:function(){return this.beanDefinition.beanMeta},enumerable:!0,configurable:!0}),e.prototype.forceUpdate=function(e){var t=(this.beanMeta.statedFields||[]).find((function(t){return t.name===e}));void 0!==t&&this.beanObserver.publishStateAction(t,this.beanObserver.proxy[e])},e}();function _(e,t){if(t in e)return e[t]}function m(e){var t=_(e,"afterProvided");return void 0!==t&&"function"==typeof t}function B(e){var t=_(e,"destroy");return void 0!==t&&"function"==typeof t}function O(e){var t=_(e,"setBeanContainer");return void 0!==t&&"function"==typeof t}var P=function(){function e(e,t,r){this._bean=e,this._container=t,this._beanDefinition=r,this.state$=new v,this.effect$=new n.Subject,this.props$=new n.Subject,this._proxyBean=new Proxy(this.origin,{});var o=this._observe();this._stateSubscription=o.state$.subscribe(this.state$),O(this.proxy)&&this.proxy.setBeanContainer(this._container)}return Object.defineProperty(e.prototype,"beanDefinition",{get:function(){return this._beanDefinition},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"proxy",{get:function(){return this._proxyBean},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"origin",{get:function(){return this._bean},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"beanMeta",{get:function(){return this.beanDefinition.beanMeta},enumerable:!0,configurable:!0}),e.prototype.destroy=function(){this.state$.complete(),this.effect$.complete(),B(this.proxy)&&this.proxy.destroy(),void 0!==this._stateSubscription&&this._stateSubscription.unsubscribe()},e.prototype.publishStateAction=function(e,t){var n={bean:this.proxy,nextValue:t,prevValue:this.proxy[e.name],fieldMeta:e};this.state$.next(n)},e.prototype._observe=function(){var e=this,t=this._defineStatedBean(this.proxy),n=this.beanMeta.propsFields;return void 0!==n&&(n.forEach((function(t){e._initPropsField(e.proxy,t,e.beanDefinition.props)})),this.props$.subscribe((function(t){n.forEach((function(n){e._updatePropsField(e.proxy,n,t)}))}))),setTimeout((function(){null!=e.beanMeta.postMethod&&void 0!==e.beanMeta.postMethod.descriptor?e.beanMeta.postMethod.descriptor.value.apply(e.proxy):m(e.proxy)&&e.proxy.afterProvided()}),0),t},e.prototype._defineStatedBean=function(e){var t=this,n=l(e);void 0===n&&(n=new g(this),Object.defineProperty(e,p,{value:n}),(this.beanMeta.statedFields||[]).forEach((function(r){t._observeBeanField(n,e,r)})));return n},e.prototype._observeBeanField=function(e,t,n){var r=Symbol(n.name.toString()+"_v");Object.defineProperty(t,r,{writable:!0,value:t[n.name]}),Object.defineProperty(t,n.name.toString(),{set:function(o){t[r]=o;var i={bean:t,nextValue:o,prevValue:t[n.name],fieldMeta:n};e.state$.next(i)},get:function(){return t[r]}})},e.prototype._initPropsField=function(e,t,r){var o=void 0===r?void 0:r[t.prop];t.observable?Reflect.set(e,t.name,new n.BehaviorSubject(o)):Reflect.set(e,t.name,o)},e.prototype._updatePropsField=function(e,t,n){var r=void 0===n?void 0:n[t.prop],o=Reflect.get(e,t.name);if(t.observable){var i=o;Object.is(i.getValue(),r)||i.next(r)}else Object.is(o,r)||Reflect.set(e,t.name,r)},e}(),j=function(){function e(e){this._container=e,this._typedBeans=new WeakMap,this._namedBeans=new Map}return Object.defineProperty(e.prototype,"beanFactory",{get:function(){return this._container.application.getBeanFactory()},enumerable:!0,configurable:!0}),e.prototype.getTypedBean=function(e){return this._typedBeans.get(e)},e.prototype.getNamedBean=function(e){return this._namedBeans.get(e)},e.prototype.register=function(e){if(e.isNamedBean)return this.registerNamedBean(e);var t=this.createBeanObserver(e);return this._addTypedBean(e.beanType,t),t},e.prototype.registerNamedBean=function(e){var t=this.getNamedBean(e.beanName);if(void 0!==t)return t;var n=this.createBeanObserver(e);return this._namedBeans.set(e.beanName,n),this._addTypedBean(e.beanType,n),n},e.prototype.createBeanObserver=function(e){var t=this,n=this.beanFactory.createBean(e);e.setTarget(n);var r=new P(n,this._container,e);r.state$.subscribeCount((function(e){0===e&&(t.remove(r),r.destroy())}));var o=l(n);return void 0!==o&&o.state$.subscribeCount((function(r){0===r&&(t.beanFactory.destroyBean(e,n),o.state$.complete())})),r},e.prototype.remove=function(e){var t=e.beanDefinition;this._namedBeans.delete(t.beanName);var n=this._typedBeans.get(t.beanType);if(void 0!==n){var r=n.indexOf(e);n.splice(r,1)}},e.prototype._addTypedBean=function(e,t){var n=this._typedBeans.get(e);void 0===n?this._typedBeans.set(e,[t]):n.unshift(t)},e}(),w=function(){function e(e,t){this._parent=e,null!=t?this._app=t:null!=this._parent&&null!=this._parent.application?this._app=this._parent.application:this._app=new u,this._registry=new j(this)}return e.prototype.destroy=function(){},e.prototype.getBeanRegistry=function(){return this._registry},e.prototype.getTypedObserver=function(e){var t=this.getBeanRegistry().getTypedBean(e);return null==t&&this.parent&&(t=this.parent.getTypedObserver(e)),t},e.prototype.getNamedObserver=function(e){var t=this.getBeanRegistry().getNamedBean(e);return null==t&&this.parent&&(t=this.parent.getNamedObserver(e)),t},e.prototype.register=function(e){return this.getBeanRegistry().register(e)},Object.defineProperty(e.prototype,"parent",{get:function(){return this._parent},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"application",{get:function(){return this._app},enumerable:!0,configurable:!0}),e}();function F(e,t,n){var r=n.value;if("function"!=typeof r)throw new TypeError("@boundMethod decorator can only be applied to methods not: "+typeof r);var o=!1;return{configurable:!0,get:function(){if(o||this===e.prototype||Object.hasOwnProperty.call(this,t)||"function"!=typeof r)return r;var n=r.bind(this);return o=!0,Object.defineProperty(this,t,{configurable:!0,get:function(){return n},set:function(e){r=e,delete this[t]}}),o=!1,n},set:function(e){r=e}}}function S(e){var t;return"undefined"!=typeof Reflect&&"function"==typeof Reflect.ownKeys?t=Reflect.ownKeys(e.prototype):(t=Object.getOwnPropertyNames(e.prototype),"function"==typeof Object.getOwnPropertySymbols&&(t=t.concat(Object.getOwnPropertySymbols(e.prototype)))),t.forEach((function(t){if("constructor"!==t){var n=Object.getOwnPropertyDescriptor(e.prototype,t);void 0!==n&&"function"==typeof n.value&&Object.defineProperty(e.prototype,t,F(e,t,n))}})),e}var M,x=function(){function e(){this._beans=new WeakMap,this._statedFields=new WeakMap,this._propsFields=new WeakMap,this._postMethod=new WeakMap}return e.prototype.collectStatedBean=function(e){var t=e.target,n=this._statedFields.get(t);e.statedFields=n,e.propsFields=this._propsFields.get(t),e.postMethod=this._postMethod.get(t),this._beans.set(t,e),this._statedFields.delete(t),this._propsFields.delete(t),this._postMethod.delete(t)},e.prototype.collectStatedField=function(e){var t=e.target,n=this._statedFields.get(t);n?n.push(e):this._statedFields.set(t,[e])},e.prototype.collectPropsField=function(e){var t=e.target,n=this._propsFields.get(t);n?n.push(e):this._propsFields.set(t,[e])},e.prototype.collectPostProvided=function(e){this._postMethod.set(e.target,e)},e.prototype.getBeanMeta=function(e){return this._beans.get(e)},e.prototype.clear=function(){this._beans=new WeakMap,this._statedFields=new WeakMap,this._propsFields=new WeakMap,this._postMethod=new WeakMap},e}(),E=function(){return M||(M=new x)},$=Symbol("UN_NAMED_BEAN"),T=function(){function e(e){this._beanProvider=e}return e.prototype.getFactory=function(){return this._beanProvider.factory},e.prototype.getFactoryBeanType=function(){return void 0!==this.target?this.target.constructor:this.beanType},e.prototype.setTarget=function(e){this._target=e,this.isPlainObject&&Object.keys(e).forEach((function(t){"function"==typeof e[t]&&Object.defineProperty(e,t,{value:e[t].bind(e)})}))},Object.defineProperty(e.prototype,"target",{get:function(){return this._target},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"beanType",{get:function(){return this._beanProvider.type},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isSingleton",{get:function(){return!!(this._beanProvider.singleton||this.beanMeta&&this.beanMeta.singleton)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"beanName",{get:function(){var e=this._beanProvider.name||this.beanMeta.name;return this.isSingleton?e||this.beanType.name:e||$},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"beanMeta",{get:function(){var e=E(),t=this.isFactoryBean?this.getFactoryBeanType():this.beanType,n=e.getBeanMeta(t);return void 0===n?{target:t,name:this._beanProvider.name,statedFields:(h(this.target)||[]).map((function(e){return{name:e,target:t}}))}:n},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isNamedBean",{get:function(){return this.beanName!==$},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isFactoryBean",{get:function(){return b(this._beanProvider.factory)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isPlainObject",{get:function(){return this.isFactoryBean?"Object"===this.getFactoryBeanType().name:"Object"===this.beanType.name},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"props",{get:function(){return this._beanProvider.props},enumerable:!0,configurable:!0}),e}();function C(e){var n=e.providers,r=e.application,o=a(),i=t.useContext(o),s=t.useState((function(){var e=new w(i.container,r);return(n||[]).forEach((function(t){var n;n=b(t)?d(t)?{type:t}:{type:t.constructor,factory:t}:t,e.register(new T(n)).state$.subscribe()})),e}))[0];return t.useEffect((function(){return function(){s.destroy()}}),[s]),s}e.AfterProvided=function(){return function(e,t,n){return void 0===n&&(n=Object.getOwnPropertyDescriptor(e,t)),E().collectPostProvided({name:t,target:e.constructor,descriptor:n}),n}},e.BeanDefinition=T,e.BeanObserver=P,e.BeanWrapper=g,e.DefaultBeanFactory=s,e.Effect=function(e){return function(t,n,o){void 0===o&&(o=Object.getOwnPropertyDescriptor(t,n));var i=e||n,a=o.value;return o.value=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=l(this);if(void 0!==n){var o=function(e){var t=n.beanObserver;void 0!==t&&t.effect$.next(r.__assign({effect:i},e))};o({loading:!0,error:null});var s=a.apply(this,e);return y(s)?s.then((function(e){return o({data:e}),e})).catch((function(e){throw o({loading:!1,error:e}),e})).finally((function(){o({loading:!1})})):(o({loading:!1,data:s}),s)}return a.apply(this,e)},o}},e.ForceUpdate=f,e.ObservableProps=function(e){return function(t,n){var r=e;void 0===r&&(r=String(n)).endsWith("$")&&(r=r.substring(0,r.length-1)),E().collectPropsField({name:n,prop:r,target:t.constructor,observable:!0})}},e.Props=function(e){return function(t,n){E().collectPropsField({name:n,prop:e||String(n),target:t.constructor,observable:!1})}},e.Stated=function(){return function(e,t){E().collectStatedField({name:t,target:e.constructor})}},e.StatedBean=function(e){return function(t){var n="object"==typeof e?e.name:e,r="object"==typeof e&&e.singleton;S(t),Object.defineProperty(t,c,{writable:!1,value:!0}),E().collectStatedBean({name:n,target:t,singleton:r})}},e.StatedBeanApplication=u,e.StatedBeanClass=c,e.StatedBeanConsumer=function(e){var t=e.children,n=a();return i.createElement(n.Consumer,null,(function(e){return t(e)}))},e.StatedBeanContainer=w,e.StatedBeanProvider=function(e){var t=e.providers,n=e.application,r=e.children,o=a(),s=C({providers:t,application:n});return i.createElement(o.Provider,{value:{container:s}},r)},e.StatedBeanWrapper=p,e.UN_NAMED_BEAN=$,e.boundClass=S,e.boundMethod=F,e.getBeanWrapper=l,e.getPropertiesWithoutFunction=h,e.getProperty=_,e.getStatedBeanContext=a,e.isBeanContainerAware=O,e.isDisposableBean=B,e.isFunction=b,e.isInitializingBean=m,e.isPromise=y,e.isStatedBeanClass=d,e.useBean=function(e,n){var r,o,i=a(),s=t.useContext(i),u=t.useState(0)[1];void 0!==n&&("object"==typeof n?(r=n.name,o=n.props):"string"!=typeof n&&"symbol"!=typeof n||(r=n));var c=t.useCallback((function(e){u((function(e){return e+1}))}),[]),p=s.container;if(void 0===p)throw new Error("not found stated bean container.");var f=t.useState((function(){var t;if(b(e)&&!d(e)){var n=e;t={type:n.constructor,factory:n,name:r,props:o}}else t={type:e,name:r,props:o};return p.register(new T(t))}))[0],l=t.useState((function(){return f.state$.subscribe(c)}))[0];return t.useEffect((function(){f.props$.next(o)}),[o,f]),t.useEffect((function(){return function(){return l.unsubscribe()}}),[l]),f.proxy},e.useContainer=C,e.useInject=function(e){var n=a(),r=t.useContext(n),o=t.useState(0)[1],i="object"==typeof e?e.type:e,s="object"==typeof e?e:{},u=s.name,c=s.observedFields,p=t.useCallback((function(e){(null==c||0===c.length||c.includes(e.fieldMeta.name))&&o((function(e){return e+1}))}),[c]),f=r.container;if(void 0===f)throw new Error("not found container");var b=t.useState((function(){var e;if(void 0!==u)e=f.getNamedObserver(u);else if(void 0!==i){var t=f.getTypedObserver(i);if(void 0!==t){if(!(t.length<=1))throw new Error("Multiple bean ["+i.name+"] found.");e=t[0]}}return e}))[0];if(void 0===b)throw new Error("bean observer is undefined.");var d=t.useState((function(){return b.state$.subscribe(p)}))[0];return t.useEffect((function(){return function(){d.unsubscribe()}}),[d]),b.proxy},e.useObservable=function(e){var r=t.useState((function(){return e instanceof n.BehaviorSubject?e.getValue():null})),o=r[0],i=r[1],a=t.useState(e),s=a[0],u=a[1];return t.useEffect((function(){b(e)||u(e)}),[e]),t.useEffect((function(){var e;return s instanceof n.Observable&&(e=s.subscribe(i)),function(){e&&e.unsubscribe()}}),[s]),o},e.useObserveEffect=function(e,n){var r=a();if(void 0===t.useContext(r).container)throw new Error("not found container");var o=t.useState((function(){return{loading:!1,error:null,data:null,effect:n}})),i=o[0],s=o[1],u=t.useCallback((function(e){e.effect===n&&s(e)}),[n]),c=t.useState((function(){var t=l(e);if(void 0===t)throw new Error("bean observer is undefined");return t.beanObserver.effect$.subscribe(u)}))[0];return t.useEffect((function(){return function(){c.unsubscribe()}}),[c]),i},Object.defineProperty(e,"__esModule",{value:!0})}));
{
"name": "stated-bean",
"version": "0.8.0",
"version": "0.8.1",
"description": "A light but scalable state management library with react hooks",

@@ -5,0 +5,0 @@ "repository": "git@github.com:mjolnirjs/stated-bean.git",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc