mobx-react-lite
Advanced tools
Comparing version 3.2.0 to 3.2.1
# mobx-react-lite | ||
## 3.2.1 | ||
### Patch Changes | ||
- [`320544a5`](https://github.com/mobxjs/mobx/commit/320544a5d0defb1a1524c83c7a5d0a9dee9de001) [#2983](https://github.com/mobxjs/mobx/pull/2983) Thanks [@urugator](https://github.com/urugator)! - Allow force update to be called infinitely times | ||
* [`10c762cc`](https://github.com/mobxjs/mobx/commit/10c762cce4871f3599bac6acc2c56776e0b4badd) [#2995](https://github.com/mobxjs/mobx/pull/2995) Thanks [@Bnaya](https://github.com/Bnaya)! - Reduce useObserver gc pressure | ||
## 3.2.0 | ||
@@ -4,0 +12,0 @@ |
@@ -44,14 +44,2 @@ 'use strict'; | ||
var EMPTY_ARRAY = []; | ||
function useForceUpdate() { | ||
var _useState = React.useState(0), | ||
setTick = _useState[1]; | ||
var update = React.useCallback(function () { | ||
setTick(function (tick) { | ||
return tick + 1; | ||
}); | ||
}, EMPTY_ARRAY); | ||
return update; | ||
} | ||
var deprecatedMessages = []; | ||
@@ -328,2 +316,6 @@ function useDeprecated(msg) { | ||
function objectToBeRetainedByReactFactory() { | ||
return new ObjectToBeRetainedByReact(); | ||
} | ||
function useObserver(fn, baseComponentName) { | ||
@@ -338,9 +330,16 @@ if (baseComponentName === void 0) { | ||
var _React$useState = React__default.useState(new ObjectToBeRetainedByReact()), | ||
objectRetainedByReact = _React$useState[0]; | ||
var _React$useState = React__default.useState(objectToBeRetainedByReactFactory), | ||
objectRetainedByReact = _React$useState[0]; // Force update, see #2982 | ||
var forceUpdate = useForceUpdate(); // StrictMode/ConcurrentMode/Suspense may mean that our component is | ||
var _React$useState2 = React__default.useState(), | ||
setState = _React$useState2[1]; | ||
var forceUpdate = function forceUpdate() { | ||
return setState([]); | ||
}; // StrictMode/ConcurrentMode/Suspense may mean that our component is | ||
// rendered and abandoned multiple times, so we need to track leaked | ||
// Reactions. | ||
var reactionTrackingRef = React__default.useRef(null); | ||
@@ -347,0 +346,0 @@ |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,r=require("mobx"),t=require("react"),n=(e=t)&&"object"==typeof e&&"default"in e?e.default:e,o=require("react-dom");if(!t.useState)throw new Error("mobx-react-lite requires React with Hooks support");if(!r.makeObservable)throw new Error("mobx-react-lite@3 requires mobx at least version 6 to be available");function u(e){e()}function i(e){e||(e=u),r.configure({reactionScheduler:e})}var a=[];function c(e){return r.getDependencyTree(e)}var s="undefined"==typeof FinalizationRegistry?void 0:FinalizationRegistry;function f(e){return{reaction:e,mounted:!1,changedBeforeMount:!1,cleanAt:Date.now()+l}}var l=1e4;function d(e){var r=new Map,t=1,n=new e((function(e){var t=r.get(e);t&&(t.reaction.dispose(),r.delete(e))}));return{addReactionToTrack:function(e,o,u){var i=t++;return n.register(u,i,e),e.current=f(o),e.current.finalizationRegistryCleanupToken=i,r.set(i,e.current),e.current},recordReactionAsCommitted:function(e){n.unregister(e),e.current&&e.current.finalizationRegistryCleanupToken&&r.delete(e.current.finalizationRegistryCleanupToken)},forceCleanupTimerToRunNowForTests:function(){},resetCleanupScheduleForTests:function(){}}}function v(){return(v=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e}).apply(this,arguments)}function p(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}function b(){var e,r=new Set;function t(){void 0===e&&(e=setTimeout(n,1e4))}function n(){e=void 0;var n=Date.now();r.forEach((function(e){var t=e.current;t&&n>=t.cleanAt&&(t.reaction.dispose(),e.current=null,r.delete(e))})),r.size>0&&t()}return{addReactionToTrack:function(e,n,o){return e.current=f(n),r.add(e),t(),e.current},recordReactionAsCommitted:function(e){r.delete(e)},forceCleanupTimerToRunNowForTests:function(){e&&(clearTimeout(e),n())},resetCleanupScheduleForTests:function(){if(r.size>0){for(var t,n=function(e,r){var t;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(t=function(e,r){if(e){if("string"==typeof e)return p(e,void 0);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?p(e,void 0):void 0}}(e))){t&&(e=t);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(t=e[Symbol.iterator]()).next.bind(t)}(r);!(t=n()).done;){var o=t.value,u=o.current;u&&(u.reaction.dispose(),o.current=null)}r.clear()}e&&(clearTimeout(e),e=void 0)}}}var m=s?d(s):b(),y=m.addReactionToTrack,g=m.recordReactionAsCommitted,h=m.resetCleanupScheduleForTests,w=!1;function T(e){w=e}function R(){return w}function S(e){return"observer"+e}var x=function(){};function O(e,o){if(void 0===o&&(o="observed"),R())return e();var u,i=n.useState(new x)[0],s=(u=t.useState(0)[1],t.useCallback((function(){u((function(e){return e+1}))}),a)),f=n.useRef(null);if(!f.current)var l=new r.Reaction(S(o),(function(){d.mounted?s():d.changedBeforeMount=!0})),d=y(f,l,i);var v,p,b=f.current.reaction;if(n.useDebugValue(b,c),n.useEffect((function(){return g(f),f.current?(f.current.mounted=!0,f.current.changedBeforeMount&&(f.current.changedBeforeMount=!1,s())):(f.current={reaction:new r.Reaction(S(o),(function(){s()})),mounted:!0,changedBeforeMount:!1,cleanAt:Infinity},s()),function(){f.current.reaction.dispose(),f.current=null}}),[]),b.track((function(){try{v=e()}catch(e){p=e}})),p)throw p;return v}var A={$$typeof:!0,render:!0,compare:!0,type:!0};function C(e){var r=e.children||e.render;return"function"!=typeof r?null:O(r)}function j(e){var n=t.useState((function(){return r.observable(e,{},{deep:!1})}))[0];return r.runInAction((function(){Object.assign(n,e)})),n}C.displayName="Observer",i(o.unstable_batchedUpdates),exports.Observer=C,exports.clearTimers=h,exports.enableStaticRendering=T,exports.isObserverBatched=function(){return!0},exports.isUsingStaticRendering=R,exports.observer=function(e,r){if(R())return e;var n,o,u,i=v({forwardRef:!1},r),a=e.displayName||e.name,c=function(r,t){return O((function(){return e(r,t)}),a)};return c.displayName=a,n=t.memo(i.forwardRef?t.forwardRef(c):c),o=e,u=n,Object.keys(o).forEach((function(e){A[e]||Object.defineProperty(u,e,Object.getOwnPropertyDescriptor(o,e))})),n.displayName=a,n},exports.observerBatching=i,exports.useAsObservableSource=j,exports.useLocalObservable=function(e,n){return t.useState((function(){return r.observable(e(),n,{autoBind:!0})}))[0]},exports.useLocalStore=function(e,n){var o=n&&j(n);return t.useState((function(){return r.observable(e(o),void 0,{autoBind:!0})}))[0]},exports.useObserver=function(e,r){return void 0===r&&(r="observed"),O(e,r)},exports.useStaticRendering=function(e){T(e)}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,r=require("mobx"),t=require("react"),n=(e=t)&&"object"==typeof e&&"default"in e?e.default:e,o=require("react-dom");if(!t.useState)throw new Error("mobx-react-lite requires React with Hooks support");if(!r.makeObservable)throw new Error("mobx-react-lite@3 requires mobx at least version 6 to be available");function u(e){e()}function i(e){e||(e=u),r.configure({reactionScheduler:e})}function a(e){return r.getDependencyTree(e)}var c="undefined"==typeof FinalizationRegistry?void 0:FinalizationRegistry;function s(e){return{reaction:e,mounted:!1,changedBeforeMount:!1,cleanAt:Date.now()+f}}var f=1e4;function l(e){var r=new Map,t=1,n=new e((function(e){var t=r.get(e);t&&(t.reaction.dispose(),r.delete(e))}));return{addReactionToTrack:function(e,o,u){var i=t++;return n.register(u,i,e),e.current=s(o),e.current.finalizationRegistryCleanupToken=i,r.set(i,e.current),e.current},recordReactionAsCommitted:function(e){n.unregister(e),e.current&&e.current.finalizationRegistryCleanupToken&&r.delete(e.current.finalizationRegistryCleanupToken)},forceCleanupTimerToRunNowForTests:function(){},resetCleanupScheduleForTests:function(){}}}function d(){return(d=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e}).apply(this,arguments)}function v(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}function p(){var e,r=new Set;function t(){void 0===e&&(e=setTimeout(n,1e4))}function n(){e=void 0;var n=Date.now();r.forEach((function(e){var t=e.current;t&&n>=t.cleanAt&&(t.reaction.dispose(),e.current=null,r.delete(e))})),r.size>0&&t()}return{addReactionToTrack:function(e,n,o){return e.current=s(n),r.add(e),t(),e.current},recordReactionAsCommitted:function(e){r.delete(e)},forceCleanupTimerToRunNowForTests:function(){e&&(clearTimeout(e),n())},resetCleanupScheduleForTests:function(){if(r.size>0){for(var t,n=function(e,r){var t;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(t=function(e,r){if(e){if("string"==typeof e)return v(e,void 0);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?v(e,void 0):void 0}}(e))){t&&(e=t);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(t=e[Symbol.iterator]()).next.bind(t)}(r);!(t=n()).done;){var o=t.value,u=o.current;u&&(u.reaction.dispose(),o.current=null)}r.clear()}e&&(clearTimeout(e),e=void 0)}}}var b=c?l(c):p(),m=b.addReactionToTrack,y=b.recordReactionAsCommitted,g=b.resetCleanupScheduleForTests,h=!1;function w(e){h=e}function T(){return h}function R(e){return"observer"+e}var S=function(){};function x(){return new S}function O(e,t){if(void 0===t&&(t="observed"),T())return e();var o=n.useState(x)[0],u=n.useState()[1],i=function(){return u([])},c=n.useRef(null);if(!c.current)var s=new r.Reaction(R(t),(function(){f.mounted?i():f.changedBeforeMount=!0})),f=m(c,s,o);var l,d,v=c.current.reaction;if(n.useDebugValue(v,a),n.useEffect((function(){return y(c),c.current?(c.current.mounted=!0,c.current.changedBeforeMount&&(c.current.changedBeforeMount=!1,i())):(c.current={reaction:new r.Reaction(R(t),(function(){i()})),mounted:!0,changedBeforeMount:!1,cleanAt:Infinity},i()),function(){c.current.reaction.dispose(),c.current=null}}),[]),v.track((function(){try{l=e()}catch(e){d=e}})),d)throw d;return l}var A={$$typeof:!0,render:!0,compare:!0,type:!0};function C(e){var r=e.children||e.render;return"function"!=typeof r?null:O(r)}function j(e){var n=t.useState((function(){return r.observable(e,{},{deep:!1})}))[0];return r.runInAction((function(){Object.assign(n,e)})),n}C.displayName="Observer",i(o.unstable_batchedUpdates),exports.Observer=C,exports.clearTimers=g,exports.enableStaticRendering=w,exports.isObserverBatched=function(){return!0},exports.isUsingStaticRendering=T,exports.observer=function(e,r){if(T())return e;var n,o,u,i=d({forwardRef:!1},r),a=e.displayName||e.name,c=function(r,t){return O((function(){return e(r,t)}),a)};return c.displayName=a,n=t.memo(i.forwardRef?t.forwardRef(c):c),o=e,u=n,Object.keys(o).forEach((function(e){A[e]||Object.defineProperty(u,e,Object.getOwnPropertyDescriptor(o,e))})),n.displayName=a,n},exports.observerBatching=i,exports.useAsObservableSource=j,exports.useLocalObservable=function(e,n){return t.useState((function(){return r.observable(e(),n,{autoBind:!0})}))[0]},exports.useLocalStore=function(e,n){var o=n&&j(n);return t.useState((function(){return r.observable(e(o),void 0,{autoBind:!0})}))[0]},exports.useObserver=function(e,r){return void 0===r&&(r="observed"),O(e,r)},exports.useStaticRendering=function(e){w(e)}; | ||
//# sourceMappingURL=mobxreactlite.cjs.production.min.js.map |
import { makeObservable, configure, getDependencyTree, Reaction, observable, runInAction } from 'mobx'; | ||
import React, { useState, useCallback, memo, forwardRef } from 'react'; | ||
import React, { useState, memo, forwardRef } from 'react'; | ||
import { unstable_batchedUpdates } from 'react-dom'; | ||
@@ -37,14 +37,2 @@ | ||
var EMPTY_ARRAY = []; | ||
function useForceUpdate() { | ||
var _useState = useState(0), | ||
setTick = _useState[1]; | ||
var update = useCallback(function () { | ||
setTick(function (tick) { | ||
return tick + 1; | ||
}); | ||
}, EMPTY_ARRAY); | ||
return update; | ||
} | ||
var deprecatedMessages = []; | ||
@@ -321,2 +309,6 @@ function useDeprecated(msg) { | ||
function objectToBeRetainedByReactFactory() { | ||
return new ObjectToBeRetainedByReact(); | ||
} | ||
function useObserver(fn, baseComponentName) { | ||
@@ -331,9 +323,16 @@ if (baseComponentName === void 0) { | ||
var _React$useState = React.useState(new ObjectToBeRetainedByReact()), | ||
objectRetainedByReact = _React$useState[0]; | ||
var _React$useState = React.useState(objectToBeRetainedByReactFactory), | ||
objectRetainedByReact = _React$useState[0]; // Force update, see #2982 | ||
var forceUpdate = useForceUpdate(); // StrictMode/ConcurrentMode/Suspense may mean that our component is | ||
var _React$useState2 = React.useState(), | ||
setState = _React$useState2[1]; | ||
var forceUpdate = function forceUpdate() { | ||
return setState([]); | ||
}; // StrictMode/ConcurrentMode/Suspense may mean that our component is | ||
// rendered and abandoned multiple times, so we need to track leaked | ||
// Reactions. | ||
var reactionTrackingRef = React.useRef(null); | ||
@@ -340,0 +339,0 @@ |
import { makeObservable, configure, getDependencyTree, Reaction, observable, runInAction } from 'mobx'; | ||
import React, { useState, useCallback, memo, forwardRef } from 'react'; | ||
import React, { useState, memo, forwardRef } from 'react'; | ||
import { unstable_batchedUpdates } from 'react-dom'; | ||
@@ -37,14 +37,2 @@ | ||
var EMPTY_ARRAY = []; | ||
function useForceUpdate() { | ||
var _useState = useState(0), | ||
setTick = _useState[1]; | ||
var update = useCallback(function () { | ||
setTick(function (tick) { | ||
return tick + 1; | ||
}); | ||
}, EMPTY_ARRAY); | ||
return update; | ||
} | ||
var deprecatedMessages = []; | ||
@@ -321,2 +309,6 @@ function useDeprecated(msg) { | ||
function objectToBeRetainedByReactFactory() { | ||
return new ObjectToBeRetainedByReact(); | ||
} | ||
function useObserver(fn, baseComponentName) { | ||
@@ -331,9 +323,16 @@ if (baseComponentName === void 0) { | ||
var _React$useState = React.useState(new ObjectToBeRetainedByReact()), | ||
objectRetainedByReact = _React$useState[0]; | ||
var _React$useState = React.useState(objectToBeRetainedByReactFactory), | ||
objectRetainedByReact = _React$useState[0]; // Force update, see #2982 | ||
var forceUpdate = useForceUpdate(); // StrictMode/ConcurrentMode/Suspense may mean that our component is | ||
var _React$useState2 = React.useState(), | ||
setState = _React$useState2[1]; | ||
var forceUpdate = function forceUpdate() { | ||
return setState([]); | ||
}; // StrictMode/ConcurrentMode/Suspense may mean that our component is | ||
// rendered and abandoned multiple times, so we need to track leaked | ||
// Reactions. | ||
var reactionTrackingRef = React.useRef(null); | ||
@@ -340,0 +339,0 @@ |
@@ -1,2 +0,2 @@ | ||
import{makeObservable as e,configure as r,getDependencyTree as n,Reaction as t,observable as o,runInAction as i}from"mobx";import u,{useState as a,useCallback as c,memo as f,forwardRef as s}from"react";import{unstable_batchedUpdates as d}from"react-dom";if(!a)throw new Error("mobx-react-lite requires React with Hooks support");if(!e)throw new Error("mobx-react-lite@3 requires mobx at least version 6 to be available");function l(e){e()}function v(e){e||(e=l),r({reactionScheduler:e})}var p=function(){return!0},m=[];function y(e){return n(e)}var b="undefined"==typeof FinalizationRegistry?void 0:FinalizationRegistry;function h(e){return{reaction:e,mounted:!1,changedBeforeMount:!1,cleanAt:Date.now()+g}}var g=1e4;function w(e){var r=new Map,n=1,t=new e((function(e){var n=r.get(e);n&&(n.reaction.dispose(),r.delete(e))}));return{addReactionToTrack:function(e,o,i){var u=n++;return t.register(i,u,e),e.current=h(o),e.current.finalizationRegistryCleanupToken=u,r.set(u,e.current),e.current},recordReactionAsCommitted:function(e){t.unregister(e),e.current&&e.current.finalizationRegistryCleanupToken&&r.delete(e.current.finalizationRegistryCleanupToken)},forceCleanupTimerToRunNowForTests:function(){},resetCleanupScheduleForTests:function(){}}}function T(){return(T=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var n=arguments[r];for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(e[t]=n[t])}return e}).apply(this,arguments)}function R(e,r){(null==r||r>e.length)&&(r=e.length);for(var n=0,t=new Array(r);n<r;n++)t[n]=e[n];return t}function O(){var e,r=new Set;function n(){void 0===e&&(e=setTimeout(t,1e4))}function t(){e=void 0;var t=Date.now();r.forEach((function(e){var n=e.current;n&&t>=n.cleanAt&&(n.reaction.dispose(),e.current=null,r.delete(e))})),r.size>0&&n()}return{addReactionToTrack:function(e,t,o){return e.current=h(t),r.add(e),n(),e.current},recordReactionAsCommitted:function(e){r.delete(e)},forceCleanupTimerToRunNowForTests:function(){e&&(clearTimeout(e),t())},resetCleanupScheduleForTests:function(){if(r.size>0){for(var n,t=function(e,r){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=function(e,r){if(e){if("string"==typeof e)return R(e,void 0);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?R(e,void 0):void 0}}(e))){n&&(e=n);var t=0;return function(){return t>=e.length?{done:!0}:{done:!1,value:e[t++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(n=e[Symbol.iterator]()).next.bind(n)}(r);!(n=t()).done;){var o=n.value,i=o.current;i&&(i.reaction.dispose(),o.current=null)}r.clear()}e&&(clearTimeout(e),e=void 0)}}}var A=b?w(b):O(),C=A.addReactionToTrack,S=A.recordReactionAsCommitted,j=A.resetCleanupScheduleForTests,k=!1;function z(e){k=e}function B(){return k}function F(e){return"observer"+e}var M=function(){};function x(e,r){if(void 0===r&&(r="observed"),B())return e();var n,o=u.useState(new M)[0],i=(n=a(0)[1],c((function(){n((function(e){return e+1}))}),m)),f=u.useRef(null);if(!f.current)var s=new t(F(r),(function(){d.mounted?i():d.changedBeforeMount=!0})),d=C(f,s,o);var l,v,p=f.current.reaction;if(u.useDebugValue(p,y),u.useEffect((function(){return S(f),f.current?(f.current.mounted=!0,f.current.changedBeforeMount&&(f.current.changedBeforeMount=!1,i())):(f.current={reaction:new t(F(r),(function(){i()})),mounted:!0,changedBeforeMount:!1,cleanAt:Infinity},i()),function(){f.current.reaction.dispose(),f.current=null}}),[]),p.track((function(){try{l=e()}catch(e){v=e}})),v)throw v;return l}function E(e,r){if(B())return e;var n,t,o,i=T({forwardRef:!1},r),u=e.displayName||e.name,a=function(r,n){return x((function(){return e(r,n)}),u)};return a.displayName=u,n=f(i.forwardRef?s(a):a),t=e,o=n,Object.keys(t).forEach((function(e){N[e]||Object.defineProperty(o,e,Object.getOwnPropertyDescriptor(t,e))})),n.displayName=u,n}var N={$$typeof:!0,render:!0,compare:!0,type:!0};function D(e){var r=e.children||e.render;return"function"!=typeof r?null:x(r)}function I(e,r){return a((function(){return o(e(),r,{autoBind:!0})}))[0]}function P(e){var r=a((function(){return o(e,{},{deep:!1})}))[0];return i((function(){Object.assign(r,e)})),r}function $(e,r){var n=r&&P(r);return a((function(){return o(e(n),void 0,{autoBind:!0})}))[0]}function q(e,r){return void 0===r&&(r="observed"),x(e,r)}function H(e){z(e)}D.displayName="Observer",v(d);export{D as Observer,j as clearTimers,z as enableStaticRendering,p as isObserverBatched,B as isUsingStaticRendering,E as observer,v as observerBatching,P as useAsObservableSource,I as useLocalObservable,$ as useLocalStore,q as useObserver,H as useStaticRendering}; | ||
import{makeObservable as e,configure as r,getDependencyTree as n,Reaction as t,observable as o,runInAction as i}from"mobx";import u,{useState as a,memo as c,forwardRef as f}from"react";import{unstable_batchedUpdates as s}from"react-dom";if(!a)throw new Error("mobx-react-lite requires React with Hooks support");if(!e)throw new Error("mobx-react-lite@3 requires mobx at least version 6 to be available");function d(e){e()}function l(e){e||(e=d),r({reactionScheduler:e})}var v=function(){return!0};function p(e){return n(e)}var m="undefined"==typeof FinalizationRegistry?void 0:FinalizationRegistry;function y(e){return{reaction:e,mounted:!1,changedBeforeMount:!1,cleanAt:Date.now()+b}}var b=1e4;function h(e){var r=new Map,n=1,t=new e((function(e){var n=r.get(e);n&&(n.reaction.dispose(),r.delete(e))}));return{addReactionToTrack:function(e,o,i){var u=n++;return t.register(i,u,e),e.current=y(o),e.current.finalizationRegistryCleanupToken=u,r.set(u,e.current),e.current},recordReactionAsCommitted:function(e){t.unregister(e),e.current&&e.current.finalizationRegistryCleanupToken&&r.delete(e.current.finalizationRegistryCleanupToken)},forceCleanupTimerToRunNowForTests:function(){},resetCleanupScheduleForTests:function(){}}}function g(){return(g=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var n=arguments[r];for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(e[t]=n[t])}return e}).apply(this,arguments)}function w(e,r){(null==r||r>e.length)&&(r=e.length);for(var n=0,t=new Array(r);n<r;n++)t[n]=e[n];return t}function T(){var e,r=new Set;function n(){void 0===e&&(e=setTimeout(t,1e4))}function t(){e=void 0;var t=Date.now();r.forEach((function(e){var n=e.current;n&&t>=n.cleanAt&&(n.reaction.dispose(),e.current=null,r.delete(e))})),r.size>0&&n()}return{addReactionToTrack:function(e,t,o){return e.current=y(t),r.add(e),n(),e.current},recordReactionAsCommitted:function(e){r.delete(e)},forceCleanupTimerToRunNowForTests:function(){e&&(clearTimeout(e),t())},resetCleanupScheduleForTests:function(){if(r.size>0){for(var n,t=function(e,r){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=function(e,r){if(e){if("string"==typeof e)return w(e,void 0);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?w(e,void 0):void 0}}(e))){n&&(e=n);var t=0;return function(){return t>=e.length?{done:!0}:{done:!1,value:e[t++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(n=e[Symbol.iterator]()).next.bind(n)}(r);!(n=t()).done;){var o=n.value,i=o.current;i&&(i.reaction.dispose(),o.current=null)}r.clear()}e&&(clearTimeout(e),e=void 0)}}}var R=m?h(m):T(),O=R.addReactionToTrack,S=R.recordReactionAsCommitted,A=R.resetCleanupScheduleForTests,C=!1;function j(e){C=e}function k(){return C}function z(e){return"observer"+e}var B=function(){};function F(){return new B}function M(e,r){if(void 0===r&&(r="observed"),k())return e();var n=u.useState(F)[0],o=u.useState()[1],i=function(){return o([])},a=u.useRef(null);if(!a.current)var c=new t(z(r),(function(){f.mounted?i():f.changedBeforeMount=!0})),f=O(a,c,n);var s,d,l=a.current.reaction;if(u.useDebugValue(l,p),u.useEffect((function(){return S(a),a.current?(a.current.mounted=!0,a.current.changedBeforeMount&&(a.current.changedBeforeMount=!1,i())):(a.current={reaction:new t(z(r),(function(){i()})),mounted:!0,changedBeforeMount:!1,cleanAt:Infinity},i()),function(){a.current.reaction.dispose(),a.current=null}}),[]),l.track((function(){try{s=e()}catch(e){d=e}})),d)throw d;return s}function x(e,r){if(k())return e;var n,t,o,i=g({forwardRef:!1},r),u=e.displayName||e.name,a=function(r,n){return M((function(){return e(r,n)}),u)};return a.displayName=u,n=c(i.forwardRef?f(a):a),t=e,o=n,Object.keys(t).forEach((function(e){E[e]||Object.defineProperty(o,e,Object.getOwnPropertyDescriptor(t,e))})),n.displayName=u,n}var E={$$typeof:!0,render:!0,compare:!0,type:!0};function N(e){var r=e.children||e.render;return"function"!=typeof r?null:M(r)}function D(e,r){return a((function(){return o(e(),r,{autoBind:!0})}))[0]}function I(e){var r=a((function(){return o(e,{},{deep:!1})}))[0];return i((function(){Object.assign(r,e)})),r}function P(e,r){var n=r&&I(r);return a((function(){return o(e(n),void 0,{autoBind:!0})}))[0]}function $(e,r){return void 0===r&&(r="observed"),M(e,r)}function q(e){j(e)}N.displayName="Observer",l(s);export{N as Observer,A as clearTimers,j as enableStaticRendering,v as isObserverBatched,k as isUsingStaticRendering,x as observer,l as observerBatching,I as useAsObservableSource,D as useLocalObservable,P as useLocalStore,$ as useObserver,q as useStaticRendering}; | ||
//# sourceMappingURL=mobxreactlite.esm.production.min.js.map |
@@ -41,14 +41,2 @@ (function (global, factory) { | ||
var EMPTY_ARRAY = []; | ||
function useForceUpdate() { | ||
var _useState = React.useState(0), | ||
setTick = _useState[1]; | ||
var update = React.useCallback(function () { | ||
setTick(function (tick) { | ||
return tick + 1; | ||
}); | ||
}, EMPTY_ARRAY); | ||
return update; | ||
} | ||
var deprecatedMessages = []; | ||
@@ -325,2 +313,6 @@ function useDeprecated(msg) { | ||
function objectToBeRetainedByReactFactory() { | ||
return new ObjectToBeRetainedByReact(); | ||
} | ||
function useObserver(fn, baseComponentName) { | ||
@@ -335,9 +327,16 @@ if (baseComponentName === void 0) { | ||
var _React$useState = React__default.useState(new ObjectToBeRetainedByReact()), | ||
objectRetainedByReact = _React$useState[0]; | ||
var _React$useState = React__default.useState(objectToBeRetainedByReactFactory), | ||
objectRetainedByReact = _React$useState[0]; // Force update, see #2982 | ||
var forceUpdate = useForceUpdate(); // StrictMode/ConcurrentMode/Suspense may mean that our component is | ||
var _React$useState2 = React__default.useState(), | ||
setState = _React$useState2[1]; | ||
var forceUpdate = function forceUpdate() { | ||
return setState([]); | ||
}; // StrictMode/ConcurrentMode/Suspense may mean that our component is | ||
// rendered and abandoned multiple times, so we need to track leaked | ||
// Reactions. | ||
var reactionTrackingRef = React__default.useRef(null); | ||
@@ -344,0 +343,0 @@ |
@@ -1,2 +0,2 @@ | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("mobx"),require("react"),require("react-dom")):"function"==typeof define&&define.amd?define(["exports","mobx","react","react-dom"],r):r((e=e||self).mobxReactLite={},e.mobx,e.React,e.ReactDOM)}(this,(function(e,r,n,t){"use strict";var o="default"in n?n.default:n;if(!n.useState)throw new Error("mobx-react-lite requires React with Hooks support");if(!r.makeObservable)throw new Error("mobx-react-lite@3 requires mobx at least version 6 to be available");function i(e){e()}function u(e){e||(e=i),r.configure({reactionScheduler:e})}var a=[];function c(e){return r.getDependencyTree(e)}var f="undefined"==typeof FinalizationRegistry?void 0:FinalizationRegistry;function s(e){return{reaction:e,mounted:!1,changedBeforeMount:!1,cleanAt:Date.now()+d}}var d=1e4;function l(e){var r=new Map,n=1,t=new e((function(e){var n=r.get(e);n&&(n.reaction.dispose(),r.delete(e))}));return{addReactionToTrack:function(e,o,i){var u=n++;return t.register(i,u,e),e.current=s(o),e.current.finalizationRegistryCleanupToken=u,r.set(u,e.current),e.current},recordReactionAsCommitted:function(e){t.unregister(e),e.current&&e.current.finalizationRegistryCleanupToken&&r.delete(e.current.finalizationRegistryCleanupToken)},forceCleanupTimerToRunNowForTests:function(){},resetCleanupScheduleForTests:function(){}}}function v(){return(v=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var n=arguments[r];for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(e[t]=n[t])}return e}).apply(this,arguments)}function b(e,r){(null==r||r>e.length)&&(r=e.length);for(var n=0,t=new Array(r);n<r;n++)t[n]=e[n];return t}function p(){var e,r=new Set;function n(){void 0===e&&(e=setTimeout(t,1e4))}function t(){e=void 0;var t=Date.now();r.forEach((function(e){var n=e.current;n&&t>=n.cleanAt&&(n.reaction.dispose(),e.current=null,r.delete(e))})),r.size>0&&n()}return{addReactionToTrack:function(e,t,o){return e.current=s(t),r.add(e),n(),e.current},recordReactionAsCommitted:function(e){r.delete(e)},forceCleanupTimerToRunNowForTests:function(){e&&(clearTimeout(e),t())},resetCleanupScheduleForTests:function(){if(r.size>0){for(var n,t=function(e,r){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=function(e,r){if(e){if("string"==typeof e)return b(e,void 0);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?b(e,void 0):void 0}}(e))){n&&(e=n);var t=0;return function(){return t>=e.length?{done:!0}:{done:!1,value:e[t++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(n=e[Symbol.iterator]()).next.bind(n)}(r);!(n=t()).done;){var o=n.value,i=o.current;i&&(i.reaction.dispose(),o.current=null)}r.clear()}e&&(clearTimeout(e),e=void 0)}}}var m=f?l(f):p(),y=m.addReactionToTrack,g=m.recordReactionAsCommitted,h=m.resetCleanupScheduleForTests,R=!1;function w(e){R=e}function T(){return R}function S(e){return"observer"+e}var O=function(){};function A(e,t){if(void 0===t&&(t="observed"),T())return e();var i,u=o.useState(new O)[0],f=(i=n.useState(0)[1],n.useCallback((function(){i((function(e){return e+1}))}),a)),s=o.useRef(null);if(!s.current)var d=new r.Reaction(S(t),(function(){l.mounted?f():l.changedBeforeMount=!0})),l=y(s,d,u);var v,b,p=s.current.reaction;if(o.useDebugValue(p,c),o.useEffect((function(){return g(s),s.current?(s.current.mounted=!0,s.current.changedBeforeMount&&(s.current.changedBeforeMount=!1,f())):(s.current={reaction:new r.Reaction(S(t),(function(){f()})),mounted:!0,changedBeforeMount:!1,cleanAt:Infinity},f()),function(){s.current.reaction.dispose(),s.current=null}}),[]),p.track((function(){try{v=e()}catch(e){b=e}})),b)throw b;return v}var C={$$typeof:!0,render:!0,compare:!0,type:!0};function j(e){var r=e.children||e.render;return"function"!=typeof r?null:A(r)}function k(e){var t=n.useState((function(){return r.observable(e,{},{deep:!1})}))[0];return r.runInAction((function(){Object.assign(t,e)})),t}j.displayName="Observer",u(t.unstable_batchedUpdates),e.Observer=j,e.clearTimers=h,e.enableStaticRendering=w,e.isObserverBatched=function(){return!0},e.isUsingStaticRendering=T,e.observer=function(e,r){if(T())return e;var t,o,i,u=v({forwardRef:!1},r),a=e.displayName||e.name,c=function(r,n){return A((function(){return e(r,n)}),a)};return c.displayName=a,t=n.memo(u.forwardRef?n.forwardRef(c):c),o=e,i=t,Object.keys(o).forEach((function(e){C[e]||Object.defineProperty(i,e,Object.getOwnPropertyDescriptor(o,e))})),t.displayName=a,t},e.observerBatching=u,e.useAsObservableSource=k,e.useLocalObservable=function(e,t){return n.useState((function(){return r.observable(e(),t,{autoBind:!0})}))[0]},e.useLocalStore=function(e,t){var o=t&&k(t);return n.useState((function(){return r.observable(e(o),void 0,{autoBind:!0})}))[0]},e.useObserver=function(e,r){return void 0===r&&(r="observed"),A(e,r)},e.useStaticRendering=function(e){w(e)},Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("mobx"),require("react"),require("react-dom")):"function"==typeof define&&define.amd?define(["exports","mobx","react","react-dom"],r):r((e=e||self).mobxReactLite={},e.mobx,e.React,e.ReactDOM)}(this,(function(e,r,n,t){"use strict";var o="default"in n?n.default:n;if(!n.useState)throw new Error("mobx-react-lite requires React with Hooks support");if(!r.makeObservable)throw new Error("mobx-react-lite@3 requires mobx at least version 6 to be available");function i(e){e()}function u(e){e||(e=i),r.configure({reactionScheduler:e})}function a(e){return r.getDependencyTree(e)}var c="undefined"==typeof FinalizationRegistry?void 0:FinalizationRegistry;function f(e){return{reaction:e,mounted:!1,changedBeforeMount:!1,cleanAt:Date.now()+s}}var s=1e4;function d(e){var r=new Map,n=1,t=new e((function(e){var n=r.get(e);n&&(n.reaction.dispose(),r.delete(e))}));return{addReactionToTrack:function(e,o,i){var u=n++;return t.register(i,u,e),e.current=f(o),e.current.finalizationRegistryCleanupToken=u,r.set(u,e.current),e.current},recordReactionAsCommitted:function(e){t.unregister(e),e.current&&e.current.finalizationRegistryCleanupToken&&r.delete(e.current.finalizationRegistryCleanupToken)},forceCleanupTimerToRunNowForTests:function(){},resetCleanupScheduleForTests:function(){}}}function l(){return(l=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var n=arguments[r];for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(e[t]=n[t])}return e}).apply(this,arguments)}function v(e,r){(null==r||r>e.length)&&(r=e.length);for(var n=0,t=new Array(r);n<r;n++)t[n]=e[n];return t}function b(){var e,r=new Set;function n(){void 0===e&&(e=setTimeout(t,1e4))}function t(){e=void 0;var t=Date.now();r.forEach((function(e){var n=e.current;n&&t>=n.cleanAt&&(n.reaction.dispose(),e.current=null,r.delete(e))})),r.size>0&&n()}return{addReactionToTrack:function(e,t,o){return e.current=f(t),r.add(e),n(),e.current},recordReactionAsCommitted:function(e){r.delete(e)},forceCleanupTimerToRunNowForTests:function(){e&&(clearTimeout(e),t())},resetCleanupScheduleForTests:function(){if(r.size>0){for(var n,t=function(e,r){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=function(e,r){if(e){if("string"==typeof e)return v(e,void 0);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?v(e,void 0):void 0}}(e))){n&&(e=n);var t=0;return function(){return t>=e.length?{done:!0}:{done:!1,value:e[t++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(n=e[Symbol.iterator]()).next.bind(n)}(r);!(n=t()).done;){var o=n.value,i=o.current;i&&(i.reaction.dispose(),o.current=null)}r.clear()}e&&(clearTimeout(e),e=void 0)}}}var p=c?d(c):b(),m=p.addReactionToTrack,y=p.recordReactionAsCommitted,g=p.resetCleanupScheduleForTests,h=!1;function R(e){h=e}function w(){return h}function T(e){return"observer"+e}var S=function(){};function O(){return new S}function A(e,n){if(void 0===n&&(n="observed"),w())return e();var t=o.useState(O)[0],i=o.useState()[1],u=function(){return i([])},c=o.useRef(null);if(!c.current)var f=new r.Reaction(T(n),(function(){s.mounted?u():s.changedBeforeMount=!0})),s=m(c,f,t);var d,l,v=c.current.reaction;if(o.useDebugValue(v,a),o.useEffect((function(){return y(c),c.current?(c.current.mounted=!0,c.current.changedBeforeMount&&(c.current.changedBeforeMount=!1,u())):(c.current={reaction:new r.Reaction(T(n),(function(){u()})),mounted:!0,changedBeforeMount:!1,cleanAt:Infinity},u()),function(){c.current.reaction.dispose(),c.current=null}}),[]),v.track((function(){try{d=e()}catch(e){l=e}})),l)throw l;return d}var C={$$typeof:!0,render:!0,compare:!0,type:!0};function j(e){var r=e.children||e.render;return"function"!=typeof r?null:A(r)}function x(e){var t=n.useState((function(){return r.observable(e,{},{deep:!1})}))[0];return r.runInAction((function(){Object.assign(t,e)})),t}j.displayName="Observer",u(t.unstable_batchedUpdates),e.Observer=j,e.clearTimers=g,e.enableStaticRendering=R,e.isObserverBatched=function(){return!0},e.isUsingStaticRendering=w,e.observer=function(e,r){if(w())return e;var t,o,i,u=l({forwardRef:!1},r),a=e.displayName||e.name,c=function(r,n){return A((function(){return e(r,n)}),a)};return c.displayName=a,t=n.memo(u.forwardRef?n.forwardRef(c):c),o=e,i=t,Object.keys(o).forEach((function(e){C[e]||Object.defineProperty(i,e,Object.getOwnPropertyDescriptor(o,e))})),t.displayName=a,t},e.observerBatching=u,e.useAsObservableSource=x,e.useLocalObservable=function(e,t){return n.useState((function(){return r.observable(e(),t,{autoBind:!0})}))[0]},e.useLocalStore=function(e,t){var o=t&&x(t);return n.useState((function(){return r.observable(e(o),void 0,{autoBind:!0})}))[0]},e.useObserver=function(e,r){return void 0===r&&(r="observed"),A(e,r)},e.useStaticRendering=function(e){R(e)},Object.defineProperty(e,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=mobxreactlite.umd.production.min.js.map |
@@ -1,2 +0,1 @@ | ||
export declare function useForceUpdate(): () => void; | ||
export declare function useDeprecated(msg: string): void; |
@@ -22,3 +22,2 @@ var __read = (this && this.__read) || function (o, n) { | ||
import { isUsingStaticRendering } from "./staticRendering"; | ||
import { useForceUpdate } from "./utils/utils"; | ||
function observerComponentNameFor(baseComponentName) { | ||
@@ -35,2 +34,5 @@ return "observer" + baseComponentName; | ||
}()); | ||
function objectToBeRetainedByReactFactory() { | ||
return new ObjectToBeRetainedByReact(); | ||
} | ||
export function useObserver(fn, baseComponentName) { | ||
@@ -41,4 +43,6 @@ if (baseComponentName === void 0) { baseComponentName = "observed"; } | ||
} | ||
var _a = __read(React.useState(new ObjectToBeRetainedByReact()), 1), objectRetainedByReact = _a[0]; | ||
var forceUpdate = useForceUpdate(); | ||
var _a = __read(React.useState(objectToBeRetainedByReactFactory), 1), objectRetainedByReact = _a[0]; | ||
// Force update, see #2982 | ||
var _b = __read(React.useState(), 2), setState = _b[1]; | ||
var forceUpdate = function () { return setState([]); }; | ||
// StrictMode/ConcurrentMode/Suspense may mean that our component is | ||
@@ -45,0 +49,0 @@ // rendered and abandoned multiple times, so we need to track leaked |
@@ -1,26 +0,1 @@ | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
import { useCallback, useState } from "react"; | ||
var EMPTY_ARRAY = []; | ||
export function useForceUpdate() { | ||
var _a = __read(useState(0), 2), setTick = _a[1]; | ||
var update = useCallback(function () { | ||
setTick(function (tick) { return tick + 1; }); | ||
}, EMPTY_ARRAY); | ||
return update; | ||
} | ||
var deprecatedMessages = []; | ||
@@ -27,0 +2,0 @@ export function useDeprecated(msg) { |
@@ -28,3 +28,2 @@ "use strict"; | ||
var staticRendering_1 = require("./staticRendering"); | ||
var utils_1 = require("./utils/utils"); | ||
function observerComponentNameFor(baseComponentName) { | ||
@@ -41,2 +40,5 @@ return "observer" + baseComponentName; | ||
}()); | ||
function objectToBeRetainedByReactFactory() { | ||
return new ObjectToBeRetainedByReact(); | ||
} | ||
function useObserver(fn, baseComponentName) { | ||
@@ -47,4 +49,6 @@ if (baseComponentName === void 0) { baseComponentName = "observed"; } | ||
} | ||
var _a = __read(react_1.default.useState(new ObjectToBeRetainedByReact()), 1), objectRetainedByReact = _a[0]; | ||
var forceUpdate = utils_1.useForceUpdate(); | ||
var _a = __read(react_1.default.useState(objectToBeRetainedByReactFactory), 1), objectRetainedByReact = _a[0]; | ||
// Force update, see #2982 | ||
var _b = __read(react_1.default.useState(), 2), setState = _b[1]; | ||
var forceUpdate = function () { return setState([]); }; | ||
// StrictMode/ConcurrentMode/Suspense may mean that our component is | ||
@@ -51,0 +55,0 @@ // rendered and abandoned multiple times, so we need to track leaked |
"use strict"; | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.useDeprecated = exports.useForceUpdate = void 0; | ||
var react_1 = require("react"); | ||
var EMPTY_ARRAY = []; | ||
function useForceUpdate() { | ||
var _a = __read(react_1.useState(0), 2), setTick = _a[1]; | ||
var update = react_1.useCallback(function () { | ||
setTick(function (tick) { return tick + 1; }); | ||
}, EMPTY_ARRAY); | ||
return update; | ||
} | ||
exports.useForceUpdate = useForceUpdate; | ||
exports.useDeprecated = void 0; | ||
var deprecatedMessages = []; | ||
@@ -31,0 +5,0 @@ function useDeprecated(msg) { |
{ | ||
"name": "mobx-react-lite", | ||
"version": "3.2.0", | ||
"version": "3.2.1", | ||
"description": "Lightweight React bindings for MobX based on React 16.8+ and Hooks", | ||
@@ -53,3 +53,3 @@ "source": "src/index.ts", | ||
"devDependencies": { | ||
"mobx": "^6.1.0", | ||
"mobx": "^6.3.3", | ||
"expose-gc": "^1.0.0" | ||
@@ -56,0 +56,0 @@ }, |
import { Reaction } from "mobx" | ||
import React from "react" | ||
import { printDebugValue } from "./utils/printDebugValue" | ||
@@ -11,3 +10,2 @@ import { | ||
import { isUsingStaticRendering } from "./staticRendering" | ||
import { useForceUpdate } from "./utils/utils" | ||
@@ -23,2 +21,6 @@ function observerComponentNameFor(baseComponentName: string) { | ||
function objectToBeRetainedByReactFactory() { | ||
return new ObjectToBeRetainedByReact() | ||
} | ||
export function useObserver<T>(fn: () => T, baseComponentName: string = "observed"): T { | ||
@@ -29,6 +31,7 @@ if (isUsingStaticRendering()) { | ||
const [objectRetainedByReact] = React.useState(new ObjectToBeRetainedByReact()) | ||
const [objectRetainedByReact] = React.useState(objectToBeRetainedByReactFactory) | ||
// Force update, see #2982 | ||
const [, setState] = React.useState() | ||
const forceUpdate = () => setState([] as any) | ||
const forceUpdate = useForceUpdate() | ||
// StrictMode/ConcurrentMode/Suspense may mean that our component is | ||
@@ -35,0 +38,0 @@ // rendered and abandoned multiple times, so we need to track leaked |
@@ -1,15 +0,1 @@ | ||
import { useCallback, useState } from "react" | ||
const EMPTY_ARRAY: any[] = [] | ||
export function useForceUpdate() { | ||
const [, setTick] = useState(0) | ||
const update = useCallback(() => { | ||
setTick(tick => tick + 1) | ||
}, EMPTY_ARRAY) | ||
return update | ||
} | ||
const deprecatedMessages: string[] = [] | ||
@@ -16,0 +2,0 @@ |
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
464754
3853