react-hooks-combine
Advanced tools
Comparing version 1.1.1 to 1.2.0
@@ -0,1 +1,9 @@ | ||
# 1.2.0 | ||
- Refine withStateHandlers to avoid updates in case if there are no changes inside object | ||
- Add forwardRef param for `combine` function to support ref forwarding | ||
- Add withImperativeHandle support | ||
# 1.1.1 | ||
- Fix issue with default props. Child component only used them while Parent skiped them. | ||
# 1.1.0 | ||
@@ -2,0 +10,0 @@ - Update `combine` function by adding `transformPropsBefore` property to filter/omit/map props |
@@ -1,2 +0,2 @@ | ||
"use strict";function _interopDefault(t){return t&&"object"==typeof t&&"default"in t?t.default:t}Object.defineProperty(exports,"__esModule",{value:!0});var React=require("react"),React__default=_interopDefault(React);function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function _defineProperty(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function _objectSpread(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter(function(t){return Object.getOwnPropertyDescriptor(r,t).enumerable}))),n.forEach(function(t){_defineProperty(e,t,r[t])})}return e}function _slicedToArray(t,e){return _arrayWithHoles(t)||_iterableToArrayLimit(t,e)||_nonIterableRest()}function _toConsumableArray(t){return _arrayWithoutHoles(t)||_iterableToArray(t)||_nonIterableSpread()}function _arrayWithoutHoles(t){if(Array.isArray(t)){for(var e=0,r=new Array(t.length);e<t.length;e++)r[e]=t[e];return r}}function _arrayWithHoles(t){if(Array.isArray(t))return t}function _iterableToArray(t){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t))return Array.from(t)}function _iterableToArrayLimit(t,e){var r=[],n=!0,o=!1,i=void 0;try{for(var a,c=t[Symbol.iterator]();!(n=(a=c.next()).done)&&(r.push(a.value),!e||r.length!==e);n=!0);}catch(t){o=!0,i=t}finally{try{n||null==c.return||c.return()}finally{if(o)throw i}}return r}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance")}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}var CTOR_PATTERN=/\[object\s(\w+)\]/,baseToString=Object.prototype.toString,getInternalCtor=function(t){return _slicedToArray(baseToString.call(t).match(CTOR_PATTERN),2)[1]},isFunction=function(t){return"Function"===getInternalCtor(t)},isObject=function(t){return"Object"===getInternalCtor(t)},isPromiseLike=function(t){return t&&("Promise"===getInternalCtor(t)||isFunction(t.then)&&isFunction(t.catch))},compose=function(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return e.reduce(function(t,e){return function(){return t(e.apply(void 0,arguments))}})},isCombineConfigMode=function(t){return isObject(t[0])},unwindLoop=function(t,e){var r=Function,n=Object.entries(e).map(function(t){var e=_slicedToArray(t,1)[0];return"box.".concat(e," = useCustomHook(fns.").concat(e,", deps, state, props);")}).join("\n");return new r("useCustomHook","fns","deps","state","props","\n const box = {};\n ".concat(n,"\n return box\n ")).bind(null,t,e)},prop=function(t,e){if(null==t)return t;var r=t,n=e.split("."),o=!0,i=!1,a=void 0;try{for(var c,u=n[Symbol.iterator]();!(o=(c=u.next()).done);o=!0){var f=c.value;if(!(r=r&&r[f]))return}}catch(t){i=!0,a=t}finally{try{o||null==u.return||u.return()}finally{if(i)throw a}}return r},getDeps=function(e,t){return Array.isArray(t)?t.map(function(t){return prop(e,t)}):t},defaultProps=function(e){return function(t){if("object"!==_typeof(e))throw Error("defaultProps expects object, got a ".concat(getInternalCtor(e)));return t.defaultProps=e,t}},identity=function(t){return t},flow=function(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return function(t){return e.reduce(function(t,e){return e(t)},t)}},merge=function(t,e){return _objectSpread({},t,e)},hookBuilder=function(t){var e=t.findIndex(function(t){return!isFunction(t)});if(-1!==e)throw Error("\n Expected function,\n got a: ".concat(_typeof(t[e]),"\n on index: ").concat(e,"\n "));var r=Function,n=t.map(function(t,e){return" \n const result".concat(e," = funcs[").concat(e,"](state").concat(e,", props)\n const state").concat(e+1," = merge(result").concat(e,", state").concat(e,");\n ")}).join("\n");return new r("funcs","merge","props","\n const state0 = {};\n ".concat(n,"\n return state").concat(t.length,";\n ")).bind(null,t,merge)},combineFromConfig=function(t,n){function e(t){var e=u(t),r=_objectSpread({},e,f(e));return React__default.createElement(n,c(r))}var r=_objectSpread({hooks:[],hocs:[],transformProps:identity,transformPropsBefore:identity},t),o=r.hooks,i=r.hocs,a=r.defaultProps,c=r.transformProps,u=r.transformPropsBefore,f=hookBuilder(o);return a&&defaultProps(a)(e),flow.apply(void 0,_toConsumableArray(i))(e)},combine=function(){for(var t=arguments.length,r=new Array(t),e=0;e<t;e++)r[e]=arguments[e];return function(t){var e=isCombineConfigMode(r)?combineFromConfig(r[0],t):combineFromConfig({hooks:r},t);return e.displayName="".concat(t.displayName||t.name,"Hooked"),e}},withImperativeHandle=function(n,o,i){return function(t,e){var r=getDeps(_objectSpread({},t,e),i);React.useImperativeHandle(n,function(){return o(t,e)},r)}},withCallbacks=function(t,r){var n=unwindLoop(function(t,e,r,n){var o=isFunction(t)?t:t.func,i=getDeps(_objectSpread({},r,n),t.deps||e);return React.useCallback(o(r,n),i)},t);return function(t,e){return n(r,t,e)}},withCallback=function(n,o,i){return function(t,e){var r=getDeps(_objectSpread({},t,e),i);return _defineProperty({},n,React.useCallback(o(t,e),r))}},withStateHandlers=function(d,y){return function(t,e){for(var r=isFunction(d)?d(t,e):d,n=_slicedToArray(React.useState(r),2),o=n[0],i=n[1],a={},c=function(t){return i(_objectSpread({},o,t))},u=0,f=Object.entries(y);u<f.length;u++){var s=_slicedToArray(f[u],2),l=s[0],p=s[1];a[l]=compose(c,p(o))}return _objectSpread({},o,a)}},withLayoutEffect=function(n,o){return function(t,e){var r=getDeps(_objectSpread({},t,e),o);React.useLayoutEffect(function(){return n(t,e)},r)}},withAsyncEffect=function(t){function e(){a=!1}var a=!1,r=_objectSpread({dataName:"data"},t),c=r.asyncAction,n=r.disposeAction,u=r.dataName,f=r.deps,s=isFunction(n)?function(){e(),n()}:e;return function(r,n){var t,e=_slicedToArray(React.useState((_defineProperty(t={loading:!0},u,null),_defineProperty(t,"error",null),t)),2),o=e[0],i=e[1];return React.useEffect(function(){var t;a&&i((_defineProperty(t={loading:!0},u,o[u]),_defineProperty(t,"error",null),t));a=!0;var e=c(r,n);if(!isPromiseLike(e))throw Error("withAsyncEffect expects Promise, got a: ".concat(getInternalCtor(e)));return e.then(function(t){var e;i((_defineProperty(e={loading:!1},u,t),_defineProperty(e,"error",null),e))},function(t){var e;i((_defineProperty(e={loading:!1},u,o[u]),_defineProperty(e,"error",t),e))}),s},getDeps(_objectSpread({},r,n),f)),o}},withDebugValue=function(n,o){return function(t,e){var r=n(t,e);React.useDebugValue(r,o)}},withMemos=function(t,r){var n=unwindLoop(function(t,e,r,n){var o=isFunction(t)?t:t.func,i=getDeps(_objectSpread({},r,n),t.deps||e);return React.useMemo(function(){return o(r,n)},i)},t);return function(t,e){return n(r,t,e)}},withMemo=function(n,o,i){return function(t,e){var r=React.useMemo(function(){return o(t,e)},getDeps(_objectSpread({},t,e),i));return _defineProperty({},n,r)}},withContext=function(e,r){return function(){var t=React.useContext(r);return _defineProperty({},e,t)}},withReducer=function(t){var e=_objectSpread({dispatchName:"dispatch"},t),o=e.reducer,i=e.stateName,a=e.dispatchName,c=e.initialState,u=e.init;return function(){var t,e=_slicedToArray(React.useReducer(o,c,u),2),r=e[0],n=e[1];return _defineProperty(t={},i,r),_defineProperty(t,a,n),t}},withEffect=function(n,o){return function(t,e){var r=getDeps(_objectSpread({},t,e),o);React.useEffect(function(){return n(t,e)},r)}},withState=function(a,c,r){var u=isFunction(r)?function(t,e){return function(){return r(t,e)}}:function(){return r};return function(t,e){var r,n=_slicedToArray(React.useState(u(t,e)),2),o=n[0],i=n[1];return _defineProperty(r={},a,o),_defineProperty(r,c,i),r}},withRef=function(e,r){return function(){var t=React.useRef(r);return _defineProperty({},e,t)}};exports.combine=combine,exports.defaultProps=defaultProps,exports.flow=flow,exports.withAsyncEffect=withAsyncEffect,exports.withCallback=withCallback,exports.withCallbacks=withCallbacks,exports.withContext=withContext,exports.withDebugValue=withDebugValue,exports.withEffect=withEffect,exports.withImperativeHandle=withImperativeHandle,exports.withLayoutEffect=withLayoutEffect,exports.withMemo=withMemo,exports.withMemos=withMemos,exports.withReducer=withReducer,exports.withRef=withRef,exports.withState=withState,exports.withStateHandlers=withStateHandlers; | ||
"use strict";function _interopDefault(t){return t&&"object"==typeof t&&"default"in t?t.default:t}Object.defineProperty(exports,"__esModule",{value:!0});var React=require("react"),React__default=_interopDefault(React);function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function _defineProperty(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function _extends(){return(_extends=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t}).apply(this,arguments)}function _objectSpread(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter(function(t){return Object.getOwnPropertyDescriptor(r,t).enumerable}))),n.forEach(function(t){_defineProperty(e,t,r[t])})}return e}function _slicedToArray(t,e){return _arrayWithHoles(t)||_iterableToArrayLimit(t,e)||_nonIterableRest()}function _toConsumableArray(t){return _arrayWithoutHoles(t)||_iterableToArray(t)||_nonIterableSpread()}function _arrayWithoutHoles(t){if(Array.isArray(t)){for(var e=0,r=new Array(t.length);e<t.length;e++)r[e]=t[e];return r}}function _arrayWithHoles(t){if(Array.isArray(t))return t}function _iterableToArray(t){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t))return Array.from(t)}function _iterableToArrayLimit(t,e){var r=[],n=!0,o=!1,i=void 0;try{for(var a,c=t[Symbol.iterator]();!(n=(a=c.next()).done)&&(r.push(a.value),!e||r.length!==e);n=!0);}catch(t){o=!0,i=t}finally{try{n||null==c.return||c.return()}finally{if(o)throw i}}return r}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance")}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}var CTOR_PATTERN=/\[object\s(\w+)\]/,baseToString=Object.prototype.toString,getInternalCtor=function(t){return _slicedToArray(baseToString.call(t).match(CTOR_PATTERN),2)[1]},isFunction=function(t){return"Function"===getInternalCtor(t)},isObject=function(t){return"Object"===getInternalCtor(t)},isPromiseLike=function(t){return t&&("Promise"===getInternalCtor(t)||isFunction(t.then)&&isFunction(t.catch))},compose=function(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return e.reduce(function(t,e){return function(){return t(e.apply(void 0,arguments))}})},isCombineConfigMode=function(t){return isObject(t[0])},unwindLoop=function(t,e){var r=Function,n=Object.entries(e).map(function(t){var e=_slicedToArray(t,1)[0];return"box.".concat(e," = useCustomHook(fns.").concat(e,", deps, state, props);")}).join("\n");return new r("useCustomHook","fns","deps","state","props","\n const box = {};\n ".concat(n,"\n return box\n ")).bind(null,t,e)},prop=function(t,e){if(null==t)return t;var r=t,n=e.split("."),o=!0,i=!1,a=void 0;try{for(var c,u=n[Symbol.iterator]();!(o=(c=u.next()).done);o=!0){var f=c.value;if(!(r=r&&r[f]))return}}catch(t){i=!0,a=t}finally{try{o||null==u.return||u.return()}finally{if(i)throw a}}return r},getDeps=function(e,t){return Array.isArray(t)?t.map(function(t){return prop(e,t)}):t},defaultProps=function(e){return function(t){if("object"!==_typeof(e))throw Error("defaultProps expects object, got a ".concat(getInternalCtor(e)));return t.defaultProps=e,t}},identity=function(t){return t},flow=function(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return function(t){return e.reduce(function(t,e){return e(t)},t)}},merge=function(t,e){return _objectSpread({},t,e)},hookBuilder=function(t){var e=t.findIndex(function(t){return!isFunction(t)});if(-1!==e)throw Error("\n Expected function,\n got a: ".concat(_typeof(t[e]),"\n on index: ").concat(e,"\n "));var r=Function,n=t.map(function(t,e){return"\n const result".concat(e," = funcs[").concat(e,"](state").concat(e,", props, ref)\n const state").concat(e+1," = merge(result").concat(e,", state").concat(e,");\n ")}).join("\n");return new r("funcs","merge","props","ref","\n const state0 = {};\n ".concat(n,"\n return state").concat(t.length,";\n ")).bind(null,t,merge)},combineFromConfig=function(t,e){var r=_objectSpread({hooks:[],hocs:[],forwardRef:!1,transformProps:identity,transformPropsBefore:identity},t),n=r.hooks,o=r.hocs,i=r.forwardRef,a=r.defaultProps,c=r.transformProps,u=r.transformPropsBefore,f=hookBuilder(n),s=i?React.forwardRef:identity,l=s(e),p=s(function(t,e){var r,n=u(t),o=_objectSpread({},n,f(n,e));return i&&(r=e),React__default.createElement(l,_extends({},c(o),{ref:r}))});return a&&defaultProps(a)(p),flow.apply(void 0,_toConsumableArray(o))(p)},combine=function(){for(var t=arguments.length,r=new Array(t),e=0;e<t;e++)r[e]=arguments[e];return function(t){var e=isCombineConfigMode(r)?combineFromConfig(r[0],t):combineFromConfig({hooks:r},t);return e.displayName="".concat(t.displayName||t.name,"Hooked"),e}},withImperativeHandle=function(o,i){return function(t,e,r){var n=getDeps(_objectSpread({},t,e),i);React.useImperativeHandle(r,function(){return o(t,e)},n)}},withCallbacks=function(t,r){var n=unwindLoop(function(t,e,r,n){var o=isFunction(t)?t:t.func,i=getDeps(_objectSpread({},r,n),t.deps||e);return React.useCallback(o(r,n),i)},t);return function(t,e){return n(r,t,e)}},withCallback=function(n,o,i){return function(t,e){var r=getDeps(_objectSpread({},t,e),i);return _defineProperty({},n,React.useCallback(o(t,e),r))}},withStateHandlers=function(d,y){return function(t,e){for(var r=isFunction(d)?d(t,e):d,n=_slicedToArray(React.useState(r),2),o=n[0],i=n[1],a={},c=function(t){Object.entries(t).some(function(t){var e=_slicedToArray(t,2),r=e[0],n=e[1];return o[r]!==n})&&i(_objectSpread({},o,t))},u=0,f=Object.entries(y);u<f.length;u++){var s=_slicedToArray(f[u],2),l=s[0],p=s[1];a[l]=compose(c,p(o))}return _objectSpread({},o,a)}},withLayoutEffect=function(n,o){return function(t,e){var r=getDeps(_objectSpread({},t,e),o);React.useLayoutEffect(function(){return n(t,e)},r)}},withAsyncEffect=function(t){function e(){a=!1}var a=!1,r=_objectSpread({dataName:"data"},t),c=r.asyncAction,n=r.disposeAction,u=r.dataName,f=r.deps,s=isFunction(n)?function(){e(),n()}:e;return function(r,n){var t,e=_slicedToArray(React.useState((_defineProperty(t={loading:!0},u,null),_defineProperty(t,"error",null),t)),2),o=e[0],i=e[1];return React.useEffect(function(){var t;a&&i((_defineProperty(t={loading:!0},u,o[u]),_defineProperty(t,"error",null),t));a=!0;var e=c(r,n);if(!isPromiseLike(e))throw Error("withAsyncEffect expects Promise, got a: ".concat(getInternalCtor(e)));return e.then(function(t){var e;i((_defineProperty(e={loading:!1},u,t),_defineProperty(e,"error",null),e))},function(t){var e;i((_defineProperty(e={loading:!1},u,o[u]),_defineProperty(e,"error",t),e))}),s},getDeps(_objectSpread({},r,n),f)),o}},withDebugValue=function(n,o){return function(t,e){var r=n(t,e);React.useDebugValue(r,o)}},withMemos=function(t,r){var n=unwindLoop(function(t,e,r,n){var o=isFunction(t)?t:t.func,i=getDeps(_objectSpread({},r,n),t.deps||e);return React.useMemo(function(){return o(r,n)},i)},t);return function(t,e){return n(r,t,e)}},withMemo=function(n,o,i){return function(t,e){var r=React.useMemo(function(){return o(t,e)},getDeps(_objectSpread({},t,e),i));return _defineProperty({},n,r)}},withContext=function(e,r){return function(){var t=React.useContext(r);return _defineProperty({},e,t)}},withReducer=function(t){var e=_objectSpread({dispatchName:"dispatch"},t),o=e.reducer,i=e.stateName,a=e.dispatchName,c=e.initialState,u=e.init;return function(){var t,e=_slicedToArray(React.useReducer(o,c,u),2),r=e[0],n=e[1];return _defineProperty(t={},i,r),_defineProperty(t,a,n),t}},withEffect=function(n,o){return function(t,e){var r=getDeps(_objectSpread({},t,e),o);React.useEffect(function(){return n(t,e)},r)}},withState=function(a,c,r){var u=isFunction(r)?function(t,e){return function(){return r(t,e)}}:function(){return r};return function(t,e){var r,n=_slicedToArray(React.useState(u(t,e)),2),o=n[0],i=n[1];return _defineProperty(r={},a,o),_defineProperty(r,c,i),r}},withRef=function(e,r){return function(){var t=React.useRef(r);return _defineProperty({},e,t)}};exports.combine=combine,exports.defaultProps=defaultProps,exports.flow=flow,exports.withAsyncEffect=withAsyncEffect,exports.withCallback=withCallback,exports.withCallbacks=withCallbacks,exports.withContext=withContext,exports.withDebugValue=withDebugValue,exports.withEffect=withEffect,exports.withImperativeHandle=withImperativeHandle,exports.withLayoutEffect=withLayoutEffect,exports.withMemo=withMemo,exports.withMemos=withMemos,exports.withReducer=withReducer,exports.withRef=withRef,exports.withState=withState,exports.withStateHandlers=withStateHandlers; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"name": "react-hooks-combine", | ||
@@ -4,0 +4,0 @@ "description": "React hooks powered, recompose like utility belt for ladies and gentlemen.", |
Sorry, the diff of this file is not supported yet
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
34420
36