react-updater
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -51,2 +51,4 @@ (function (global, factory) { | ||
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -85,4 +87,2 @@ | ||
_this.cachedHandleCallbacks = {}; | ||
_this.cachedUpdateCallbacks = {}; | ||
_this.cachedUpdateCount = 0; | ||
@@ -104,21 +104,22 @@ _this.cachedHandleCount = 0; | ||
_this.handleCallbacksRefs.set(fn, _this.cachedHandleCount); | ||
var handler = function handler() { | ||
for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
args[_key2] = arguments[_key2]; | ||
} | ||
return fn.apply(undefined, _toConsumableArray(handler.values).concat(args)); | ||
}; | ||
handler.values = values; | ||
_this.handleCallbacksRefs.set(fn, handler); | ||
_this.cachedHandleCount++; | ||
} | ||
var hash = _this.handleCallbacksRefs.get(fn) + JSON.stringify(values); | ||
if (_this.cachedHandleCallbacks[hash]) { | ||
return _this.cachedHandleCallbacks[hash]; | ||
return handler; | ||
} | ||
_this.cachedHandleCallbacks[hash] = function () { | ||
for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
args[_key2] = arguments[_key2]; | ||
} | ||
var cached = _this.handleCallbacksRefs.get(fn); | ||
fn.apply(undefined, values.concat(args)); | ||
}; | ||
cached.values = values; | ||
return _this.cachedHandleCallbacks[hash]; | ||
return cached; | ||
}; | ||
@@ -135,31 +136,33 @@ | ||
console.error('Maximum "update" callbacks size exceeded. This probably is because' + ' you are creating inline handlers inside the render method,' + ' which results in a new handler on every render which can lead' + ' to de-optimizations by components that rely on props equality.'); | ||
return; | ||
} | ||
_this.updateCallbacksRefs.set(fn, _this.cachedUpdateCount); | ||
var updater = function updater() { | ||
for (var _len4 = arguments.length, args = Array(_len4), _key4 = 0; _key4 < _len4; _key4++) { | ||
args[_key4] = arguments[_key4]; | ||
} | ||
var values = updater.values; | ||
_this.setState(function (state) { | ||
if (typeof state[STATE_PROPERTY_NAME] === 'undefined') { | ||
return fn.apply(undefined, [state].concat(_toConsumableArray(values), args)); | ||
} | ||
return _defineProperty({}, STATE_PROPERTY_NAME, fn.apply(undefined, [state[STATE_PROPERTY_NAME]].concat(_toConsumableArray(values), args))); | ||
}); | ||
}; | ||
updater.values = values; | ||
_this.updateCallbacksRefs.set(fn, updater); | ||
_this.cachedUpdateCount++; | ||
} | ||
var hash = _this.updateCallbacksRefs.get(fn) + JSON.stringify(values); | ||
if (_this.cachedUpdateCallbacks[hash]) { | ||
return _this.cachedUpdateCallbacks[hash]; | ||
return updater; | ||
} | ||
_this.cachedUpdateCallbacks[hash] = function () { | ||
for (var _len4 = arguments.length, args = Array(_len4), _key4 = 0; _key4 < _len4; _key4++) { | ||
args[_key4] = arguments[_key4]; | ||
} | ||
var cached = _this.updateCallbacksRefs.get(fn); | ||
_this.setState(function (state) { | ||
if (typeof state[STATE_PROPERTY_NAME] === 'undefined') { | ||
return fn.apply(undefined, [state].concat(values, args)); | ||
} | ||
cached.values = values; | ||
return _defineProperty({}, STATE_PROPERTY_NAME, fn.apply(undefined, [state[STATE_PROPERTY_NAME]].concat(values, args))); | ||
}); | ||
}; | ||
return _this.cachedUpdateCallbacks[hash]; | ||
return cached; | ||
}; | ||
@@ -199,5 +202,3 @@ | ||
value: function componentWillUnmount() { | ||
this.cachedHandleCallbacks = null; | ||
this.cachedHandleCount = null; | ||
this.cachedUpdateCallbacks = null; | ||
this.cachedUpdateCount = null; | ||
@@ -204,0 +205,0 @@ this.handleCallbacksRefs = null; |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):e.withUpdater=t(e.React)}(this,function(e){"use strict";function t(e){return!0===o(e)&&"[object Object]"===Object.prototype.toString.call(e)}function n(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function r(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function c(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var l="default"in e?e["default"]:e,o=function(e){return null!=e&&"object"==typeof e&&!1===Array.isArray(e)},u=function(e){var n,a;return!1!==t(e)&&("function"==typeof(n=e.constructor)&&(a=n.prototype,!1!==t(a)&&!1!==a.hasOwnProperty("isPrototypeOf")))},i=function(){function e(e,t){for(var n=0;t.length>n;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}return function(t,n,a){return n&&e(t.prototype,n),a&&e(t,a),t}}(),f="@@STATE";return function(){var t=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;return function(o){return function(e){function s(e){a(this,s);var c=r(this,(s.__proto__||Object.getPrototypeOf(s)).call(this,e));if(c.cachedHandleCallbacks={},c.cachedUpdateCallbacks={},c.cachedUpdateCount=0,c.cachedHandleCount=0,c.handleCallbacksRefs=new Map,c.updateCallbacksRefs=new Map,c.handle=function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),a=1;t>a;a++)n[a-1]=arguments[a];c.handleCallbacksRefs.has(e)||(c.handleCallbacksRefs.set(e,c.cachedHandleCount),c.cachedHandleCount++);var r=c.handleCallbacksRefs.get(e)+JSON.stringify(n);return c.cachedHandleCallbacks[r]?c.cachedHandleCallbacks[r]:c.cachedHandleCallbacks[r]=function(){for(var t=arguments.length,a=Array(t),r=0;t>r;r++)a[r]=arguments[r];e.apply(undefined,n.concat(a))}},c.update=function(e){for(var t=arguments.length,a=Array(t>1?t-1:0),r=1;t>r;r++)a[r-1]=arguments[r];c.updateCallbacksRefs.has(e)||(c.updateCallbacksRefs.set(e,c.cachedUpdateCount),c.cachedUpdateCount++);var l=c.updateCallbacksRefs.get(e)+JSON.stringify(a);return c.cachedUpdateCallbacks[l]?c.cachedUpdateCallbacks[l]:c.cachedUpdateCallbacks[l]=function(){for(var t=arguments.length,r=Array(t),l=0;t>l;l++)r[l]=arguments[l];c.setState(function(t){return"undefined"==typeof t[f]?e.apply(undefined,[t].concat(a,r)):n({},f,e.apply(undefined,[t[f]].concat(a,r)))})}},"function"==typeof t){var l=t(e);c.state=u(l)?l:n({},f,l)}else c.state=u(t)?t:n({},f,t);return c}return c(s,e),i(s,[{key:"componentWillUnmount",value:function(){this.cachedHandleCallbacks=null,this.cachedHandleCount=null,this.cachedUpdateCallbacks=null,this.cachedUpdateCount=null,this.handleCallbacksRefs=null,this.updateCallbacksRefs=null}},{key:"render",value:function(){var e="undefined"==typeof this.state[f]?this.state:this.state[f];return l.createElement(o,Object.assign({},this.props,{handle:this.handle,state:e,update:this.update}))}}]),s}(e.Component)}}}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):e.withUpdater=t(e.React)}(this,function(e){"use strict";function t(e){return!0===c(e)&&"[object Object]"===Object.prototype.toString.call(e)}function n(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function r(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);e.length>t;t++)n[t]=e[t];return n}return Array.from(e)}function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function u(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var l="default"in e?e.default:e,c=function(e){return null!=e&&"object"==typeof e&&!1===Array.isArray(e)},i=function(e){var n,r;return!1!==t(e)&&("function"==typeof(n=e.constructor)&&(r=n.prototype,!1!==t(r)&&!1!==r.hasOwnProperty("isPrototypeOf")))},f=function(){function e(e,t){for(var n=0;t.length>n;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),s="@@STATE";return function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;return function(c){return function(e){function p(e){a(this,p);var u=o(this,(p.__proto__||Object.getPrototypeOf(p)).call(this,e));if(u.cachedUpdateCount=0,u.cachedHandleCount=0,u.handleCallbacksRefs=new Map,u.updateCallbacksRefs=new Map,u.handle=function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),a=1;t>a;a++)n[a-1]=arguments[a];if(!u.handleCallbacksRefs.has(e)){var o=function t(){for(var n=arguments.length,a=Array(n),o=0;n>o;o++)a[o]=arguments[o];return e.apply(void 0,r(t.values).concat(a))};return o.values=n,u.handleCallbacksRefs.set(e,o),u.cachedHandleCount++,o}var l=u.handleCallbacksRefs.get(e);return l.values=n,l},u.update=function(e){for(var t=arguments.length,a=Array(t>1?t-1:0),o=1;t>o;o++)a[o-1]=arguments[o];if(!u.updateCallbacksRefs.has(e)){var l=function t(){for(var a=arguments.length,o=Array(a),l=0;a>l;l++)o[l]=arguments[l];var c=t.values;u.setState(function(t){return void 0===t[s]?e.apply(void 0,[t].concat(r(c),o)):n({},s,e.apply(void 0,[t[s]].concat(r(c),o)))})};return l.values=a,u.updateCallbacksRefs.set(e,l),u.cachedUpdateCount++,l}var c=u.updateCallbacksRefs.get(e);return c.values=a,c},"function"==typeof t){var l=t(e);u.state=i(l)?l:n({},s,l)}else u.state=i(t)?t:n({},s,t);return u}return u(p,e),f(p,[{key:"componentWillUnmount",value:function(){this.cachedHandleCount=null,this.cachedUpdateCount=null,this.handleCallbacksRefs=null,this.updateCallbacksRefs=null}},{key:"render",value:function(){var e=void 0===this.state[s]?this.state:this.state[s];return l.createElement(c,Object.assign({},this.props,{handle:this.handle,state:e,update:this.update}))}}]),p}(e.Component)}}}); |
@@ -5,2 +5,4 @@ var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -42,4 +44,2 @@ | ||
_this.cachedHandleCallbacks = {}; | ||
_this.cachedUpdateCallbacks = {}; | ||
_this.cachedUpdateCount = 0; | ||
@@ -61,21 +61,22 @@ _this.cachedHandleCount = 0; | ||
_this.handleCallbacksRefs.set(fn, _this.cachedHandleCount); | ||
var handler = function handler() { | ||
for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
args[_key2] = arguments[_key2]; | ||
} | ||
return fn.apply(undefined, _toConsumableArray(handler.values).concat(args)); | ||
}; | ||
handler.values = values; | ||
_this.handleCallbacksRefs.set(fn, handler); | ||
_this.cachedHandleCount++; | ||
} | ||
var hash = _this.handleCallbacksRefs.get(fn) + JSON.stringify(values); | ||
if (_this.cachedHandleCallbacks[hash]) { | ||
return _this.cachedHandleCallbacks[hash]; | ||
return handler; | ||
} | ||
_this.cachedHandleCallbacks[hash] = function () { | ||
for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
args[_key2] = arguments[_key2]; | ||
} | ||
var cached = _this.handleCallbacksRefs.get(fn); | ||
fn.apply(undefined, values.concat(args)); | ||
}; | ||
cached.values = values; | ||
return _this.cachedHandleCallbacks[hash]; | ||
return cached; | ||
}; | ||
@@ -92,31 +93,33 @@ | ||
console.error('Maximum "update" callbacks size exceeded. This probably is because' + ' you are creating inline handlers inside the render method,' + ' which results in a new handler on every render which can lead' + ' to de-optimizations by components that rely on props equality.'); | ||
return; | ||
} | ||
_this.updateCallbacksRefs.set(fn, _this.cachedUpdateCount); | ||
var updater = function updater() { | ||
for (var _len4 = arguments.length, args = Array(_len4), _key4 = 0; _key4 < _len4; _key4++) { | ||
args[_key4] = arguments[_key4]; | ||
} | ||
var values = updater.values; | ||
_this.setState(function (state) { | ||
if (typeof state[STATE_PROPERTY_NAME] === 'undefined') { | ||
return fn.apply(undefined, [state].concat(_toConsumableArray(values), args)); | ||
} | ||
return _defineProperty({}, STATE_PROPERTY_NAME, fn.apply(undefined, [state[STATE_PROPERTY_NAME]].concat(_toConsumableArray(values), args))); | ||
}); | ||
}; | ||
updater.values = values; | ||
_this.updateCallbacksRefs.set(fn, updater); | ||
_this.cachedUpdateCount++; | ||
} | ||
var hash = _this.updateCallbacksRefs.get(fn) + JSON.stringify(values); | ||
if (_this.cachedUpdateCallbacks[hash]) { | ||
return _this.cachedUpdateCallbacks[hash]; | ||
return updater; | ||
} | ||
_this.cachedUpdateCallbacks[hash] = function () { | ||
for (var _len4 = arguments.length, args = Array(_len4), _key4 = 0; _key4 < _len4; _key4++) { | ||
args[_key4] = arguments[_key4]; | ||
} | ||
var cached = _this.updateCallbacksRefs.get(fn); | ||
_this.setState(function (state) { | ||
if (typeof state[STATE_PROPERTY_NAME] === 'undefined') { | ||
return fn.apply(undefined, [state].concat(values, args)); | ||
} | ||
cached.values = values; | ||
return _defineProperty({}, STATE_PROPERTY_NAME, fn.apply(undefined, [state[STATE_PROPERTY_NAME]].concat(values, args))); | ||
}); | ||
}; | ||
return _this.cachedUpdateCallbacks[hash]; | ||
return cached; | ||
}; | ||
@@ -156,5 +159,3 @@ | ||
value: function componentWillUnmount() { | ||
this.cachedHandleCallbacks = null; | ||
this.cachedHandleCount = null; | ||
this.cachedUpdateCallbacks = null; | ||
this.cachedUpdateCount = null; | ||
@@ -161,0 +162,0 @@ this.handleCallbacksRefs = null; |
@@ -21,2 +21,4 @@ 'use strict'; | ||
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -53,4 +55,2 @@ | ||
_this.cachedHandleCallbacks = {}; | ||
_this.cachedUpdateCallbacks = {}; | ||
_this.cachedUpdateCount = 0; | ||
@@ -72,21 +72,22 @@ _this.cachedHandleCount = 0; | ||
_this.handleCallbacksRefs.set(fn, _this.cachedHandleCount); | ||
var handler = function handler() { | ||
for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
args[_key2] = arguments[_key2]; | ||
} | ||
return fn.apply(undefined, _toConsumableArray(handler.values).concat(args)); | ||
}; | ||
handler.values = values; | ||
_this.handleCallbacksRefs.set(fn, handler); | ||
_this.cachedHandleCount++; | ||
} | ||
var hash = _this.handleCallbacksRefs.get(fn) + JSON.stringify(values); | ||
if (_this.cachedHandleCallbacks[hash]) { | ||
return _this.cachedHandleCallbacks[hash]; | ||
return handler; | ||
} | ||
_this.cachedHandleCallbacks[hash] = function () { | ||
for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
args[_key2] = arguments[_key2]; | ||
} | ||
var cached = _this.handleCallbacksRefs.get(fn); | ||
fn.apply(undefined, values.concat(args)); | ||
}; | ||
cached.values = values; | ||
return _this.cachedHandleCallbacks[hash]; | ||
return cached; | ||
}; | ||
@@ -103,31 +104,33 @@ | ||
console.error('Maximum "update" callbacks size exceeded. This probably is because' + ' you are creating inline handlers inside the render method,' + ' which results in a new handler on every render which can lead' + ' to de-optimizations by components that rely on props equality.'); | ||
return; | ||
} | ||
_this.updateCallbacksRefs.set(fn, _this.cachedUpdateCount); | ||
var updater = function updater() { | ||
for (var _len4 = arguments.length, args = Array(_len4), _key4 = 0; _key4 < _len4; _key4++) { | ||
args[_key4] = arguments[_key4]; | ||
} | ||
var values = updater.values; | ||
_this.setState(function (state) { | ||
if (typeof state[STATE_PROPERTY_NAME] === 'undefined') { | ||
return fn.apply(undefined, [state].concat(_toConsumableArray(values), args)); | ||
} | ||
return _defineProperty({}, STATE_PROPERTY_NAME, fn.apply(undefined, [state[STATE_PROPERTY_NAME]].concat(_toConsumableArray(values), args))); | ||
}); | ||
}; | ||
updater.values = values; | ||
_this.updateCallbacksRefs.set(fn, updater); | ||
_this.cachedUpdateCount++; | ||
} | ||
var hash = _this.updateCallbacksRefs.get(fn) + JSON.stringify(values); | ||
if (_this.cachedUpdateCallbacks[hash]) { | ||
return _this.cachedUpdateCallbacks[hash]; | ||
return updater; | ||
} | ||
_this.cachedUpdateCallbacks[hash] = function () { | ||
for (var _len4 = arguments.length, args = Array(_len4), _key4 = 0; _key4 < _len4; _key4++) { | ||
args[_key4] = arguments[_key4]; | ||
} | ||
var cached = _this.updateCallbacksRefs.get(fn); | ||
_this.setState(function (state) { | ||
if (typeof state[STATE_PROPERTY_NAME] === 'undefined') { | ||
return fn.apply(undefined, [state].concat(values, args)); | ||
} | ||
cached.values = values; | ||
return _defineProperty({}, STATE_PROPERTY_NAME, fn.apply(undefined, [state[STATE_PROPERTY_NAME]].concat(values, args))); | ||
}); | ||
}; | ||
return _this.cachedUpdateCallbacks[hash]; | ||
return cached; | ||
}; | ||
@@ -167,5 +170,3 @@ | ||
value: function componentWillUnmount() { | ||
this.cachedHandleCallbacks = null; | ||
this.cachedHandleCount = null; | ||
this.cachedUpdateCallbacks = null; | ||
this.cachedUpdateCount = null; | ||
@@ -172,0 +173,0 @@ this.handleCallbacksRefs = null; |
{ | ||
"name": "react-updater", | ||
"description": "Functional stateful components made easy", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"browser": "dist/react-updater.js", | ||
@@ -54,3 +54,3 @@ "main": "lib/index.js", | ||
"eslint-plugin-import": "^2.2.0", | ||
"eslint-plugin-react": "^6.10.3", | ||
"eslint-plugin-react": "^7.0.1", | ||
"gzip-size": "^3.0.0", | ||
@@ -63,3 +63,3 @@ "jest": "^20.0.0", | ||
"rimraf": "^2.6.1", | ||
"rollup": "^0.41.6", | ||
"rollup": "^0.42.0", | ||
"rollup-plugin-babel": "^2.7.1", | ||
@@ -69,3 +69,3 @@ "rollup-plugin-commonjs": "^8.0.2", | ||
"rollup-plugin-replace": "^1.1.1", | ||
"rollup-plugin-uglify": "^1.0.2" | ||
"rollup-plugin-uglify": "^2.0.1" | ||
}, | ||
@@ -72,0 +72,0 @@ "dependencies": { |
@@ -48,3 +48,3 @@ # React Updater | ||
export default withUpdater()(Component); | ||
export default withUpdater(0)(Component); | ||
``` | ||
@@ -65,3 +65,3 @@ | ||
export default withUpdater()(Component); | ||
export default withUpdater(0)(Component); | ||
``` | ||
@@ -68,0 +68,0 @@ |
@@ -22,4 +22,2 @@ /** | ||
return class EnhancedComponent extends Component { | ||
cachedHandleCallbacks = {}; | ||
cachedUpdateCallbacks = {}; | ||
cachedUpdateCount = 0; | ||
@@ -69,17 +67,16 @@ cachedHandleCount = 0; | ||
this.handleCallbacksRefs.set(fn, this.cachedHandleCount); | ||
const handler = (...args) => fn(...handler.values, ...args); | ||
handler.values = values; | ||
this.handleCallbacksRefs.set(fn, handler); | ||
this.cachedHandleCount++; | ||
return handler; | ||
} | ||
const hash = this.handleCallbacksRefs.get(fn) + JSON.stringify(values); | ||
const cached = this.handleCallbacksRefs.get(fn); | ||
if (this.cachedHandleCallbacks[hash]) { | ||
return this.cachedHandleCallbacks[hash]; | ||
} | ||
cached.values = values; | ||
this.cachedHandleCallbacks[hash] = (...args) => { | ||
fn(...values, ...args); | ||
}; | ||
return this.cachedHandleCallbacks[hash]; | ||
return cached; | ||
}; | ||
@@ -111,39 +108,38 @@ | ||
); | ||
return; | ||
} | ||
this.updateCallbacksRefs.set(fn, this.cachedUpdateCount); | ||
const updater = (...args) => { | ||
const { values } = updater; | ||
this.setState(state => { | ||
if (typeof state[STATE_PROPERTY_NAME] === 'undefined') { | ||
return fn(state, ...values, ...args); | ||
} | ||
return { | ||
[STATE_PROPERTY_NAME]: fn( | ||
state[STATE_PROPERTY_NAME], | ||
...values, | ||
...args | ||
) | ||
}; | ||
}); | ||
}; | ||
updater.values = values; | ||
this.updateCallbacksRefs.set(fn, updater); | ||
this.cachedUpdateCount++; | ||
} | ||
const hash = this.updateCallbacksRefs.get(fn) + JSON.stringify(values); | ||
if (this.cachedUpdateCallbacks[hash]) { | ||
return this.cachedUpdateCallbacks[hash]; | ||
return updater; | ||
} | ||
this.cachedUpdateCallbacks[hash] = (...args) => { | ||
this.setState(state => { | ||
if (typeof state[STATE_PROPERTY_NAME] === 'undefined') { | ||
return fn(state, ...values, ...args); | ||
} | ||
const cached = this.updateCallbacksRefs.get(fn); | ||
return { | ||
[STATE_PROPERTY_NAME]: fn( | ||
state[STATE_PROPERTY_NAME], | ||
...values, | ||
...args | ||
) | ||
}; | ||
}); | ||
}; | ||
cached.values = values; | ||
return this.cachedUpdateCallbacks[hash]; | ||
return cached; | ||
}; | ||
componentWillUnmount() { | ||
this.cachedHandleCallbacks = null; | ||
this.cachedHandleCount = null; | ||
this.cachedUpdateCallbacks = null; | ||
this.cachedUpdateCount = null; | ||
@@ -150,0 +146,0 @@ this.handleCallbacksRefs = null; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
43159
591