@joenoon/mobx-react-hooks
Version:
React Hooks for MobX
2 lines (1 loc) • 1.55 kB
JavaScript
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("mobx"),require("react")):"function"==typeof define&&define.amd?define(["exports","mobx","react"],r):r((e=e||self).mobxReact={},e.mobx,e.React)}(this,function(e,r,t){"use strict";if(!t.useState)throw new Error("@joenoon/mobx-react-hooks requires React with Hooks support");if(!r.spy)throw new Error("@joenoon/mobx-react-hooks requires mobx at least version 4 to be available");var n=!1;function o(){return n}function u(e){return e.current?r.getDependencyTree(e.current):"<unknown>"}function i(){var e=function(e,r){var t="function"==typeof Symbol&&e[Symbol.iterator];if(!t)return e;var n,o,u=t.call(e),i=[];try{for(;(void 0===r||r-- >0)&&!(n=u.next()).done;)i.push(n.value)}catch(e){o={error:e}}finally{try{n&&!n.done&&(t=u.return)&&t.call(u)}finally{if(o)throw o.error}}return i}(t.useState(0),2)[1];return t.useCallback(function(){e(function(e){return e+1})},[])}var c={};e.isUsingStaticRendering=o,e.useForceUpdate=i,e.useObserverInternal=function(e,n,a){if(void 0===n&&(n="observed"),void 0===a&&(a=c),o())return e();var f,s,l=(a.useForceUpdate||i)(),d=t.useRef(null),b=t.useRef(!1);if(d.current||(d.current=new r.Reaction("observer("+n+")",function(){b.current&&l()})),t.useDebugValue(d,u),t.useEffect(function(){return b.current=!0,function(){return d.current.dispose()}},[]),d.current.track(function(){try{f=e()}catch(e){s=e}}),s)throw d.current.dispose(),s;return f},e.useStaticRendering=function(e){n=e},Object.defineProperty(e,"__esModule",{value:!0})});