(function(a,b){'object'==typeof exports&&'undefined'!=typeof module?b(exports,require('react')):'function'==typeof define&&define.amd?define(['exports','react'],b):b(a.easyState={},a.react)})(this,function(a,b){'use strict';function c(a){y.set(a,Object.create(null))}function d(a,b){var c=b.target,d=b.key,e=b.type;'iterate'===e&&(d=z);var f=y.get(c),g=f[d];g||(f[d]=g=new Set),g.has(a)||(g.add(a),a.cleaners.push(g))}function e(a){var b=a.target,c=a.key,d=a.type,e=y.get(b),g=new Set;if('clear'===d)for(var h in e)f(g,e,h);else f(g,e,c);if('add'===d||'delete'===d||'clear'===d){var i=Array.isArray(b)?'length':z;f(g,e,i)}return g}function f(a,b,c){var d=b[c];d&&d.forEach(a.add,a)}function g(a){a.cleaners&&a.cleaners.forEach(h,a),a.cleaners=[]}function h(a){a.delete(this)}function i(a,b,c,d){if(a.unobserved)return b.apply(c,d);g(a);try{return x=a,b.apply(c,d)}finally{x=void 0}}function j(a){x&&(m(x,a),d(x,a))}function k(a){e(a).forEach(l,a)}function l(a){m(a,this),'function'==typeof a.scheduler?a.scheduler(a):'object'==typeof a.scheduler?a.scheduler.add(a):a()}function m(a,b){if(a.debugger&&!A)try{A=!0,a.debugger(b)}finally{A=!1}}function n(){return x!==void 0}function o(a,b){void 0===b&&(b={});var c=a[B]?a:function b(){return i(b,a,this,arguments)};return c.scheduler=b.scheduler,c.debugger=b.debugger,c[B]=!0,b.lazy||c(),c}function p(a){a.unobserved||(a.unobserved=!0,g(a)),'object'==typeof a.scheduler&&a.scheduler.delete(a)}function q(a){var b=a.constructor,c='function'==typeof b&&b.name in I&&I[b.name]===b;return!c||J.has(b)}function r(a){return J.get(a.constructor)}function s(a){return void 0===a&&(a={}),C.has(a)||!q(a)?a:D.get(a)||t(a)}function t(a){var b=r(a)||L,d=new Proxy(a,b);return D.set(a,d),C.set(d,a),c(a),d}function u(a){return C.has(a)}function v(a){return C.get(a)||a}function w(a){const b=a[M];return Object.keys(b).map(a=>b[a]).filter(u).map(v)}var x,y=new WeakMap,z=Symbol('iteration key'),A=!1,B=Symbol('is reaction'),C=new WeakMap,D=new WeakMap,E=Object.getPrototypeOf,F=Object.prototype.hasOwnProperty,G={has:function(a){var b=C.get(this),c=E(this);return j({target:b,key:a,type:'has'}),c.has.apply(b,arguments)},get:function(a){var b=C.get(this),c=E(this);return j({target:b,key:a,type:'get'}),c.get.apply(b,arguments)},add:function(a){var b=C.get(this),c=E(this),d=c.has.call(b,a),e=c.add.apply(b,arguments);return d||k({target:b,key:a,value:a,type:'add'}),e},set:function(a,b){var c=C.get(this),d=E(this),e=d.has.call(c,a),f=d.get.call(c,a),g=d.set.apply(c,arguments);return e?b!==f&&k({target:c,key:a,value:b,oldValue:f,type:'set'}):k({target:c,key:a,value:b,type:'add'}),g},delete:function(a){var b=C.get(this),c=E(this),d=c.has.call(b,a),e=c.get?c.get.call(b,a):void 0,f=c.delete.apply(b,arguments);return d&&k({target:b,key:a,oldValue:e,type:'delete'}),f},clear:function(){var a=C.get(this),b=E(this),c=0!==a.size,d=a instanceof Map?new Map(a):new Set(a),e=b.clear.apply(a,arguments);return c&&k({target:a,oldTarget:d,type:'clear'}),e},forEach:function(){var a=C.get(this),b=E(this);return j({target:a,type:'iterate'}),b.forEach.apply(a,arguments)},keys:function(){var a=C.get(this),b=E(this);return j({target:a,type:'iterate'}),b.keys.apply(a,arguments)},values:function(){var a=C.get(this),b=E(this);return j({target:a,type:'iterate'}),b.values.apply(a,arguments)},entries:function(){var a=C.get(this),b=E(this);return j({target:a,type:'iterate'}),b.entries.apply(a,arguments)},get size(){var a=C.get(this),b=E(this);return j({target:a,type:'iterate'}),Reflect.get(b,'size',a)}};G[Symbol.iterator]=function(){var a=C.get(this),b=E(this);return j({target:a,type:'iterate'}),b[Symbol.iterator].apply(a,arguments)};var H={get:function(a,b,c){return a=F.call(G,b)?G:a,Reflect.get(a,b,c)}},I=Function('return this')(),J=new Map([[Map,H],[Set,H],[WeakMap,H],[WeakSet,H],[Object,!1],[Array,!1],[Int8Array,!1],[Uint8Array,!1],[Uint8ClampedArray,!1],[Int16Array,!1],[Uint16Array,!1],[Int32Array,!1],[Uint32Array,!1],[Float32Array,!1],[Float64Array,!1]]),K=Object.prototype.hasOwnProperty,L={get:function(a,b,c){var d=Reflect.get(a,b,c);if('symbol'==typeof b||'function'==typeof d)return d;j({target:a,key:b,receiver:c,type:'get'});var e=D.get(d);if(n()&&'object'==typeof d&&null!==d){if(e)return e;var f=Reflect.getOwnPropertyDescriptor(a,b);if(!f||!1!==f.writable||!1!==f.configurable)return s(d)}return e||d},has:function(a,b){var c=Reflect.has(a,b);return'symbol'==typeof b?c:(j({target:a,key:b,type:'has'}),c)},ownKeys:function(a){return j({target:a,type:'iterate'}),Reflect.ownKeys(a)},set:function(a,b,c,d){'object'==typeof c&&null!==c&&(c=C.get(c)||c);var e=K.call(a,b),f=a[b],g=Reflect.set(a,b,c,d);return n()?(console.error('Mutating observables in reactions is forbidden. You set '+b+' to '+c+'.'),g):'symbol'==typeof b||a!==C.get(d)?g:(e?c!==f&&k({target:a,key:b,value:c,oldValue:f,receiver:d,type:'set'}):k({target:a,key:b,value:c,receiver:d,type:'add'}),g)},deleteProperty:function(a,b){var c=K.call(a,b),d=a[b],e=Reflect.deleteProperty(a,b);return'symbol'!=typeof b&&c&&k({target:a,key:b,oldValue:d,type:'delete'}),e}};const M=Symbol('owner component'),N={};a.store=s,a.view=function(a,{devtool:c}={}){const d=!(a.prototype&&a.prototype.isReactComponent),e=d?b.Component:a,f=c?b=>c(Object.assign({Component:a},b)):void 0;class g extends e{constructor(a,b){super(a,b),this.state=this.state||{},this.state[M]=this,this.render=o(this.render,{scheduler:()=>this.setState(N),debugger:f,lazy:!0})}render(){return d?a(this.props,this.context):super.render()}shouldComponentUpdate(a,b){const{props:c,state:d}=this;if(super.shouldComponentUpdate&&!super.shouldComponentUpdate(a,b))return f&&f({type:'render',renderType:'blocked'}),!1;if(d!==b)return f&&f({type:'render',renderType:'reactive'}),!0;const e=Object.keys(c),g=Object.keys(a);return!!(g.length!==e.length||g.some(b=>c[b]!==a[b]))&&(f&&f({type:'render',renderType:'normal',props:a,oldProps:c}),!0)}static getDerivedStateFromProps(a,b){if(super.deriveStoresFromProps){const c=w(b);super.deriveStoresFromProps(a,...c)}return super.getDerivedStateFromProps?super.getDerivedStateFromProps(a,b):null}componentWillUnmount(){super.componentWillUnmount&&super.componentWillUnmount(),p(this.render)}}if(g.displayName=a.displayName||a.name,d)for(let b of Object.keys(a))g[b]=a[b];return g},Object.defineProperty(a,'__esModule',{value:!0})});