mobx-react-lite
Advanced tools
Comparing version 1.0.1 to 1.1.0
@@ -129,2 +129,9 @@ (function (global, factory) { | ||
function printDebugValue(v) { | ||
if (!v.current) { | ||
return "<unknown>"; | ||
} | ||
return mobx.getDependencyTree(v.current); | ||
} | ||
var EMPTY_ARRAY = []; | ||
@@ -154,2 +161,3 @@ function useUnmount(fn) { | ||
} | ||
react.useDebugValue(reaction, printDebugValue); | ||
useUnmount(function () { | ||
@@ -162,5 +170,15 @@ reaction.current.dispose(); | ||
var rendering; | ||
var exception; | ||
reaction.current.track(function () { | ||
rendering = fn(); | ||
try { | ||
rendering = fn(); | ||
} | ||
catch (e) { | ||
exception = e; | ||
} | ||
}); | ||
if (exception) { | ||
reaction.current.dispose(); | ||
throw exception; // re-throw any exceptions catched during rendering | ||
} | ||
return rendering; | ||
@@ -194,5 +212,20 @@ } | ||
} | ||
copyStaticProperties(baseComponent, memoComponent); | ||
memoComponent.displayName = baseComponentName; | ||
return memoComponent; | ||
} | ||
// based on https://github.com/mridgway/hoist-non-react-statics/blob/master/src/index.js | ||
var hoistBlackList = { | ||
$$typeof: true, | ||
render: true, | ||
compare: true, | ||
type: true | ||
}; | ||
function copyStaticProperties(base, target) { | ||
Object.keys(base).forEach(function (key) { | ||
if (base.hasOwnProperty(key) && !hoistBlackList[key]) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(base, key)); | ||
} | ||
}); | ||
} | ||
@@ -199,0 +232,0 @@ function ObserverComponent(_a) { |
@@ -1,3 +0,3 @@ | ||
import { spy, observable, computed, Reaction } from 'mobx'; | ||
import { useState, useRef, useMemo, useEffect, useCallback, memo, forwardRef } from 'react'; | ||
import { spy, observable, computed, getDependencyTree, Reaction } from 'mobx'; | ||
import { useState, useRef, useMemo, useEffect, useCallback, useDebugValue, memo, forwardRef } from 'react'; | ||
@@ -126,2 +126,9 @@ if (!useState) { | ||
function printDebugValue(v) { | ||
if (!v.current) { | ||
return "<unknown>"; | ||
} | ||
return getDependencyTree(v.current); | ||
} | ||
var EMPTY_ARRAY = []; | ||
@@ -151,2 +158,3 @@ function useUnmount(fn) { | ||
} | ||
useDebugValue(reaction, printDebugValue); | ||
useUnmount(function () { | ||
@@ -159,5 +167,15 @@ reaction.current.dispose(); | ||
var rendering; | ||
var exception; | ||
reaction.current.track(function () { | ||
rendering = fn(); | ||
try { | ||
rendering = fn(); | ||
} | ||
catch (e) { | ||
exception = e; | ||
} | ||
}); | ||
if (exception) { | ||
reaction.current.dispose(); | ||
throw exception; // re-throw any exceptions catched during rendering | ||
} | ||
return rendering; | ||
@@ -191,5 +209,20 @@ } | ||
} | ||
copyStaticProperties(baseComponent, memoComponent); | ||
memoComponent.displayName = baseComponentName; | ||
return memoComponent; | ||
} | ||
// based on https://github.com/mridgway/hoist-non-react-statics/blob/master/src/index.js | ||
var hoistBlackList = { | ||
$$typeof: true, | ||
render: true, | ||
compare: true, | ||
type: true | ||
}; | ||
function copyStaticProperties(base, target) { | ||
Object.keys(base).forEach(function (key) { | ||
if (base.hasOwnProperty(key) && !hoistBlackList[key]) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(base, key)); | ||
} | ||
}); | ||
} | ||
@@ -196,0 +229,0 @@ function ObserverComponent(_a) { |
@@ -129,2 +129,9 @@ (function (global, factory) { | ||
function printDebugValue(v) { | ||
if (!v.current) { | ||
return "<unknown>"; | ||
} | ||
return mobx.getDependencyTree(v.current); | ||
} | ||
var EMPTY_ARRAY = []; | ||
@@ -154,2 +161,3 @@ function useUnmount(fn) { | ||
} | ||
react.useDebugValue(reaction, printDebugValue); | ||
useUnmount(function () { | ||
@@ -162,5 +170,15 @@ reaction.current.dispose(); | ||
var rendering; | ||
var exception; | ||
reaction.current.track(function () { | ||
rendering = fn(); | ||
try { | ||
rendering = fn(); | ||
} | ||
catch (e) { | ||
exception = e; | ||
} | ||
}); | ||
if (exception) { | ||
reaction.current.dispose(); | ||
throw exception; // re-throw any exceptions catched during rendering | ||
} | ||
return rendering; | ||
@@ -194,5 +212,20 @@ } | ||
} | ||
copyStaticProperties(baseComponent, memoComponent); | ||
memoComponent.displayName = baseComponentName; | ||
return memoComponent; | ||
} | ||
// based on https://github.com/mridgway/hoist-non-react-statics/blob/master/src/index.js | ||
var hoistBlackList = { | ||
$$typeof: true, | ||
render: true, | ||
compare: true, | ||
type: true | ||
}; | ||
function copyStaticProperties(base, target) { | ||
Object.keys(base).forEach(function (key) { | ||
if (base.hasOwnProperty(key) && !hoistBlackList[key]) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(base, key)); | ||
} | ||
}); | ||
} | ||
@@ -199,0 +232,0 @@ function ObserverComponent(_a) { |
@@ -1,1 +0,1 @@ | ||
!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,n){"use strict";if(!n.useState)throw new Error("mobx-react-lite requires React with Hooks support");if(!r.spy)throw new Error("mobx-react-lite requires mobx at least version 4 to be available");var t=function(){};var o=!1;function u(){return o}var i=function(){return(i=Object.assign||function(e){for(var r,n=1,t=arguments.length;n<t;n++)for(var o in r=arguments[n])Object.prototype.hasOwnProperty.call(r,o)&&(e[o]=r[o]);return e}).apply(this,arguments)};var c=[];function f(){var e=function(e,r){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var t,o,u=n.call(e),i=[];try{for(;(void 0===r||r-- >0)&&!(t=u.next()).done;)i.push(t.value)}catch(e){o={error:e}}finally{try{t&&!t.done&&(n=u.return)&&n.call(u)}finally{if(o)throw o.error}}return i}(n.useState(0),2)[1];return n.useCallback(function(){e(function(e){return e+1})},[])}function a(e,t){if(void 0===t&&(t="observed"),u())return e();var o,i=f(),a=n.useRef(null);return a.current||(a.current=new r.Reaction("observer("+t+")",function(){i()})),function(e){n.useEffect(function(){return e},c)}(function(){a.current.dispose()}),a.current.track(function(){o=e()}),o}function s(e){var r=e.children,n=e.render,t=r||n;return"function"!=typeof t?null:a(t)}function l(e,r,n,t,o){var u="children"===r?"render":"children",i="function"==typeof e[r],c="function"==typeof e[u];return i&&c?new Error("MobX Observer: Do not use children and render in the same time in`"+n):i||c?null:new Error("Invalid prop `"+o+"` of type `"+typeof e[r]+"` supplied to `"+n+"`, expected `function`.")}s.propTypes={children:l,render:l},s.displayName="Observer",e.useObservable=function(e){var t=n.useRef(null);return t.current||(t.current=r.observable(e)),t.current},e.useComputed=function(e,t){return void 0===t&&(t=[]),n.useMemo(function(){return r.computed(e)},t).get()},e.useDisposable=function(e,r){void 0===r&&(r=[]);var o=n.useRef(null),u=n.useRef(!1);function i(r){if(u.current)return t;if(!o.current){var n=e();if("function"!=typeof n){var i=new Error("generated disposer must be a function");return console.error(i),t}o.current=n}return function(){o.current&&(o.current(),o.current=null),r&&(u.current=!0)}}return n.useEffect(function(){return i(!1)},r),i(!0)},e.isUsingStaticRendering=u,e.useStaticRendering=function(e){o=e},e.observer=function(e,r){if(u())return e;var t,o=i({forwardRef:!1},r),c=e.displayName||e.name,f=function(r,n){return a(function(){return e(r,n)},c)};return(t=o.forwardRef?n.memo(n.forwardRef(f)):n.memo(f)).displayName=c,t},e.useObserver=a,e.Observer=s,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!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,n){"use strict";if(!n.useState)throw new Error("mobx-react-lite requires React with Hooks support");if(!r.spy)throw new Error("mobx-react-lite requires mobx at least version 4 to be available");var t=function(){};var o=!1;function u(){return o}var i=function(){return(i=Object.assign||function(e){for(var r,n=1,t=arguments.length;n<t;n++)for(var o in r=arguments[n])Object.prototype.hasOwnProperty.call(r,o)&&(e[o]=r[o]);return e}).apply(this,arguments)};function c(e){return e.current?r.getDependencyTree(e.current):"<unknown>"}var f=[];function a(){var e=function(e,r){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var t,o,u=n.call(e),i=[];try{for(;(void 0===r||r-- >0)&&!(t=u.next()).done;)i.push(t.value)}catch(e){o={error:e}}finally{try{t&&!t.done&&(n=u.return)&&n.call(u)}finally{if(o)throw o.error}}return i}(n.useState(0),2)[1];return n.useCallback(function(){e(function(e){return e+1})},[])}function s(e,t){if(void 0===t&&(t="observed"),u())return e();var o,i,s=a(),l=n.useRef(null);if(l.current||(l.current=new r.Reaction("observer("+t+")",function(){s()})),n.useDebugValue(l,c),function(e){n.useEffect(function(){return e},f)}(function(){l.current.dispose()}),l.current.track(function(){try{o=e()}catch(e){i=e}}),i)throw l.current.dispose(),i;return o}var l={$$typeof:!0,render:!0,compare:!0,type:!0};function p(e){var r=e.children,n=e.render,t=r||n;return"function"!=typeof t?null:s(t)}function d(e,r,n,t,o){var u="children"===r?"render":"children",i="function"==typeof e[r],c="function"==typeof e[u];return i&&c?new Error("MobX Observer: Do not use children and render in the same time in`"+n):i||c?null:new Error("Invalid prop `"+o+"` of type `"+typeof e[r]+"` supplied to `"+n+"`, expected `function`.")}p.propTypes={children:d,render:d},p.displayName="Observer",e.useObservable=function(e){var t=n.useRef(null);return t.current||(t.current=r.observable(e)),t.current},e.useComputed=function(e,t){return void 0===t&&(t=[]),n.useMemo(function(){return r.computed(e)},t).get()},e.useDisposable=function(e,r){void 0===r&&(r=[]);var o=n.useRef(null),u=n.useRef(!1);function i(r){if(u.current)return t;if(!o.current){var n=e();if("function"!=typeof n){var i=new Error("generated disposer must be a function");return console.error(i),t}o.current=n}return function(){o.current&&(o.current(),o.current=null),r&&(u.current=!0)}}return n.useEffect(function(){return i(!1)},r),i(!0)},e.isUsingStaticRendering=u,e.useStaticRendering=function(e){o=e},e.observer=function(e,r){if(u())return e;var t,o,c,f=i({forwardRef:!1},r),a=e.displayName||e.name,p=function(r,n){return s(function(){return e(r,n)},a)};return t=f.forwardRef?n.memo(n.forwardRef(p)):n.memo(p),o=e,c=t,Object.keys(o).forEach(function(e){o.hasOwnProperty(e)&&!l[e]&&Object.defineProperty(c,e,Object.getOwnPropertyDescriptor(o,e))}),t.displayName=a,t},e.useObserver=s,e.Observer=p,Object.defineProperty(e,"__esModule",{value:!0})}); |
@@ -1,3 +0,3 @@ | ||
import { spy, observable, computed, Reaction } from 'mobx'; | ||
import { useState, useRef, useMemo, useEffect, useCallback, memo, forwardRef } from 'react'; | ||
import { spy, observable, computed, getDependencyTree, Reaction } from 'mobx'; | ||
import { useState, useRef, useMemo, useEffect, useCallback, useDebugValue, memo, forwardRef } from 'react'; | ||
@@ -126,2 +126,9 @@ if (!useState) { | ||
function printDebugValue(v) { | ||
if (!v.current) { | ||
return "<unknown>"; | ||
} | ||
return getDependencyTree(v.current); | ||
} | ||
var EMPTY_ARRAY = []; | ||
@@ -151,2 +158,3 @@ function useUnmount(fn) { | ||
} | ||
useDebugValue(reaction, printDebugValue); | ||
useUnmount(function () { | ||
@@ -159,5 +167,15 @@ reaction.current.dispose(); | ||
var rendering; | ||
var exception; | ||
reaction.current.track(function () { | ||
rendering = fn(); | ||
try { | ||
rendering = fn(); | ||
} | ||
catch (e) { | ||
exception = e; | ||
} | ||
}); | ||
if (exception) { | ||
reaction.current.dispose(); | ||
throw exception; // re-throw any exceptions catched during rendering | ||
} | ||
return rendering; | ||
@@ -191,5 +209,20 @@ } | ||
} | ||
copyStaticProperties(baseComponent, memoComponent); | ||
memoComponent.displayName = baseComponentName; | ||
return memoComponent; | ||
} | ||
// based on https://github.com/mridgway/hoist-non-react-statics/blob/master/src/index.js | ||
var hoistBlackList = { | ||
$$typeof: true, | ||
render: true, | ||
compare: true, | ||
type: true | ||
}; | ||
function copyStaticProperties(base, target) { | ||
Object.keys(base).forEach(function (key) { | ||
if (base.hasOwnProperty(key) && !hoistBlackList[key]) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(base, key)); | ||
} | ||
}); | ||
} | ||
@@ -196,0 +229,0 @@ function ObserverComponent(_a) { |
@@ -130,2 +130,9 @@ 'use strict'; | ||
function printDebugValue(v) { | ||
if (!v.current) { | ||
return "<unknown>"; | ||
} | ||
return mobx.getDependencyTree(v.current); | ||
} | ||
var EMPTY_ARRAY = []; | ||
@@ -155,2 +162,3 @@ function useUnmount(fn) { | ||
} | ||
react.useDebugValue(reaction, printDebugValue); | ||
useUnmount(function () { | ||
@@ -163,5 +171,15 @@ reaction.current.dispose(); | ||
var rendering; | ||
var exception; | ||
reaction.current.track(function () { | ||
rendering = fn(); | ||
try { | ||
rendering = fn(); | ||
} | ||
catch (e) { | ||
exception = e; | ||
} | ||
}); | ||
if (exception) { | ||
reaction.current.dispose(); | ||
throw exception; // re-throw any exceptions catched during rendering | ||
} | ||
return rendering; | ||
@@ -195,5 +213,20 @@ } | ||
} | ||
copyStaticProperties(baseComponent, memoComponent); | ||
memoComponent.displayName = baseComponentName; | ||
return memoComponent; | ||
} | ||
// based on https://github.com/mridgway/hoist-non-react-statics/blob/master/src/index.js | ||
var hoistBlackList = { | ||
$$typeof: true, | ||
render: true, | ||
compare: true, | ||
type: true | ||
}; | ||
function copyStaticProperties(base, target) { | ||
Object.keys(base).forEach(function (key) { | ||
if (base.hasOwnProperty(key) && !hoistBlackList[key]) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(base, key)); | ||
} | ||
}); | ||
} | ||
@@ -200,0 +233,0 @@ function ObserverComponent(_a) { |
{ | ||
"name": "mobx-react-lite", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "Lightweight React bindings for MobX based on React 16.8 and Hooks", | ||
@@ -89,3 +89,4 @@ "main": "dist/index.js", | ||
} | ||
} | ||
}, | ||
"dependencies": {} | ||
} |
277464
21
1315