UNPKG

mobx-react

Version:

React bindings for MobX. Create fully reactive components.

3 lines (2 loc) 5.43 kB
var e,t;e=this,t=function(e,t,n,r){function o(e,t){return e===t?0!==e||1/e==1/t:e!=e&&t!=t}function i(e,t,...n){t.locks++;try{let t;return null!=e&&(t=e.apply(this,n)),t}finally{t.locks--,0===t.locks&&t.methods.forEach(e=>{e.apply(this,n)})}}function c(e,t){return function(...n){i.call(this,e,t,...n)}}function u(e,t,n){const r=function(e,t){const n=e[h]=e[h]||{},r=n[t]=n[t]||{};return r.locks=r.locks||0,r.methods=r.methods||[],r}(e,t);r.methods.indexOf(n)<0&&r.methods.push(n);const o=Object.getOwnPropertyDescriptor(e,t);if(o&&o[m])return;const i=s(e,t,o?o.enumerable:void 0,r,e[t]);Object.defineProperty(e,t,i)}function s(e,t,n,r,o){let i=c(o,r);return{[m]:!0,get:function(){return i},set:function(o){if(this===e)i=c(o,r);else{const e=s(this,t,n,r,o);Object.defineProperty(this,t,e)}},configurable:!0,enumerable:n}}function l(e){var t;return null!=(t=e[p])?t:e[p]={reaction:null,mounted:!1,reactionInvalidatedBeforeMount:!1,forceUpdate:null,name:a(e.constructor),state:void 0,props:void 0,context:void 0}}function a(e){return e.displayName||e.name||"<component>"}function f(e){const n=e.bind(this),o=l(this);return function(){let e,i;if(o.reaction||(o.reaction=function(e){return new t.Reaction(`${e.name}.render()`,()=>{if(e.mounted)try{null==e.forceUpdate||e.forceUpdate()}catch(n){var t;null==(t=e.reaction)||t.dispose(),e.reaction=null}else e.reactionInvalidatedBeforeMount=!0})}(o),o.mounted||r._observerFinalizationRegistry.register(this,o,this)),o.reaction.track(()=>{try{i=t._allowStateChanges(!1,n)}catch(t){e=t}}),e)throw e;return i}}function b(e,t){return r.isUsingStaticRendering()&&console.warn("[mobx-react] It seems that a re-rendering of a React component is triggered while in static (server-side) mode. Please make sure components are rendered only once server-side."),this.state!==t||!function(e,t){if(o(e,t))return!0;if("object"!=typeof e||null===e||"object"!=typeof t||null===t)return!1;const n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(let r=0;r<n.length;r++)if(!Object.hasOwnProperty.call(t,n[r])||!o(e[n[r]],t[n[r]]))return!1;return!0}(this.props,e)}var d=function(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach(function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}}),t.default=e,t}(n);const h=Symbol("patchMixins"),m=Symbol("patchedDefinition"),p=Symbol("ObserverAdministration"),v=Symbol("isMobXReactObserver");if(!n.Component)throw new Error("mobx-react requires React to be available");if(!t.observable)throw new Error("mobx-react requires mobx to be available");Object.defineProperty(e,"Observer",{enumerable:!0,get:function(){return r.Observer}}),Object.defineProperty(e,"_observerFinalizationRegistry",{enumerable:!0,get:function(){return r._observerFinalizationRegistry}}),Object.defineProperty(e,"clearTimers",{enumerable:!0,get:function(){return r.clearTimers}}),Object.defineProperty(e,"enableStaticRendering",{enumerable:!0,get:function(){return r.enableStaticRendering}}),Object.defineProperty(e,"isUsingStaticRendering",{enumerable:!0,get:function(){return r.isUsingStaticRendering}}),Object.defineProperty(e,"useLocalObservable",{enumerable:!0,get:function(){return r.useLocalObservable}}),e.observer=function(e,t){if(t&&"class"!==t.kind)throw new Error("The @observer decorator can be used on classes only");return Object.prototype.isPrototypeOf.call(d.Component,e)||Object.prototype.isPrototypeOf.call(d.PureComponent,e)?function(e){const{prototype:t}=e;if(e[v]){const t=a(e);throw new Error(`The provided component class (${t}) has already been declared as an observer component.`)}if(e[v]=!0,t.componentWillReact)throw new Error("The componentWillReact life-cycle event is no longer supported");if(e.__proto__!==n.PureComponent)if(t.shouldComponentUpdate){if(t.shouldComponentUpdate!==b)throw new Error("It is not allowed to use shouldComponentUpdate in observer based components.")}else t.shouldComponentUpdate=b;const o=t.render;if("function"!=typeof o){const t=a(e);throw new Error(`[mobx-react] class component (${t}) is missing \`render\` method.\n\`observer\` requires \`render\` being a function defined on prototype.\n\`render = () => {}\` or \`render = function() {}\` is not supported.`)}t.render=function(){return Object.defineProperty(this,"render",{configurable:!1,writable:!1,value:r.isUsingStaticRendering()?o:f.call(this,o)}),this.render()};const i=t.componentDidMount;return t.componentDidMount=function(){const e=l(this);return e.mounted=!0,r._observerFinalizationRegistry.unregister(this),e.forceUpdate=()=>this.forceUpdate(),e.reaction&&!e.reactionInvalidatedBeforeMount||e.forceUpdate(),null==i?void 0:i.apply(this,arguments)},u(t,"componentWillUnmount",function(){var e;if(r.isUsingStaticRendering())return;const t=l(this);null==(e=t.reaction)||e.dispose(),t.reaction=null,t.forceUpdate=null,t.mounted=!1,t.reactionInvalidatedBeforeMount=!1}),e}(e):r.observer(e)},Object.defineProperty(e,"__esModule",{value:!0})},"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("mobx"),require("react"),require("mobx-react-lite")):"function"==typeof define&&define.amd?define(["exports","mobx","react","mobx-react-lite"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).mobxReact={},e.mobx,e.React,e.mobxReactLite); //# sourceMappingURL=mobxreact.umd.production.min.js.map