Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-hooks-combine

Package Overview
Dependencies
Maintainers
2
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-hooks-combine - npm Package Compare versions

Comparing version 1.3.2 to 1.3.3

3

CHANGELOG.md

@@ -0,1 +1,4 @@

# 1.3.3
- withAsyncEffect's effectHandler accepts prevStateProps object as third argument
# 1.3.2

@@ -2,0 +5,0 @@ - (withEffect, withLayoutEffect)'s effectHandler accepts prevStateProps object as third argument

2

dist/index.js

@@ -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 _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,a=void 0;try{for(var i,c=t[Symbol.iterator]();!(n=(i=c.next()).done)&&(r.push(i.value),!e||r.length!==e);n=!0);}catch(t){o=!0,a=t}finally{try{n||null==c.return||c.return()}finally{if(o)throw a}}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))},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,a=!1,i=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){a=!0,i=t}finally{try{o||null==u.return||u.return()}finally{if(a)throw i}}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,a=r.forwardRef,i=r.defaultProps,c=r.transformProps,u=r.transformPropsBefore,f=hookBuilder(n),s=a?React.forwardRef:identity,l=s(e),p=s(function(t,e){var r,n=u(t),o=_objectSpread({},n,f(n,e));return a&&(r=e),React__default.createElement(l,_extends({},c(o),{ref:r}))});return i&&defaultProps(i)(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,a){return function(t,e,r){var n=getDeps(_objectSpread({},t,e),a);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,a=getDeps(_objectSpread({},r,n),t.deps||e);return React.useCallback(o(r,n),a)},t);return function(t,e){return n(r,t,e)}},withCallback=function(n,o,a){return function(t,e){var r=getDeps(_objectSpread({},t,e),a);return _defineProperty({},n,React.useCallback(o(t,e),r))}},createWithEffect=function(i){return function(o,a){return function(e,r){var t=getDeps(_objectSpread({},e,r),a),n=React.useRef({state:e,props:r});i(function(){var t=o(e,r,n.current);return n.current={state:e,props:r},t},t)}}},withEffect=createWithEffect(React.useEffect),withLayoutEffect=createWithEffect(React.useLayoutEffect),withStateHandlers=function(r,i){var o=isFunction(r)?function(t,e){return function(){return r(t,e)}}:function(){return r},u=new WeakMap;return function(t,e){var r=_slicedToArray(React.useState(o(t,e)),2),a=r[0],c=r[1];u.has(c)||function(){var r={state:a,props:e,actionHandlers:{}};u.set(c,r);for(var t=function(){var t=_slicedToArray(o[n],2),e=t[0],i=t[1];r.actionHandlers[e]=function(){for(var t=u.get(c),e=t.state,r=t.props,n=arguments.length,o=new Array(n),a=0;a<n;a++)o[a]=arguments[a];!function(t){var o=u.get(c).state;Object.entries(t).some(function(t){var e=_slicedToArray(t,2),r=e[0],n=e[1];return o[r]!==n})&&c(_objectSpread({},o,t))}(i({args:o,state:e,props:r}))}},n=0,o=Object.entries(i);n<o.length;n++)t()}();var n=u.get(c);return n.state=a,n.props=e,_objectSpread({},a,n.actionHandlers)}},withAsyncEffect=function(t){function e(){i=!1}var i=!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],a=e[1];return React.useEffect(function(){var t;i&&a((_defineProperty(t={loading:!0},u,o[u]),_defineProperty(t,"error",null),t));i=!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;a((_defineProperty(e={loading:!1},u,t),_defineProperty(e,"error",null),e))},function(t){var e;a((_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,a=getDeps(_objectSpread({},r,n),t.deps||e);return React.useMemo(function(){return o(r,n)},a)},t);return function(t,e){return n(r,t,e)}},withMemo=function(n,o,a){return function(t,e){var r=React.useMemo(function(){return o(t,e)},getDeps(_objectSpread({},t,e),a));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,a=e.stateName,i=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={},a,r),_defineProperty(t,i,n),t}},withState=function(i,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],a=n[1];return _defineProperty(r={},i,o),_defineProperty(r,c,a),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,a=void 0;try{for(var i,c=t[Symbol.iterator]();!(n=(i=c.next()).done)&&(r.push(i.value),!e||r.length!==e);n=!0);}catch(t){o=!0,a=t}finally{try{n||null==c.return||c.return()}finally{if(o)throw a}}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))},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,a=!1,i=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){a=!0,i=t}finally{try{o||null==u.return||u.return()}finally{if(a)throw i}}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,a=r.forwardRef,i=r.defaultProps,c=r.transformProps,u=r.transformPropsBefore,f=hookBuilder(n),s=a?React.forwardRef:identity,p=s(e),l=s(function(t,e){var r,n=u(t),o=_objectSpread({},n,f(n,e));return a&&(r=e),React__default.createElement(p,_extends({},c(o),{ref:r}))});return i&&defaultProps(i)(l),flow.apply(void 0,_toConsumableArray(o))(l)},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,a){return function(t,e,r){var n=getDeps(_objectSpread({},t,e),a);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,a=getDeps(_objectSpread({},r,n),t.deps||e);return React.useCallback(o(r,n),a)},t);return function(t,e){return n(r,t,e)}},withCallback=function(n,o,a){return function(t,e){var r=getDeps(_objectSpread({},t,e),a);return _defineProperty({},n,React.useCallback(o(t,e),r))}},createWithEffect=function(i){return function(o,a){return function(e,r){var t=getDeps(_objectSpread({},e,r),a),n=React.useRef({state:e,props:r});i(function(){var t=o(e,r,n.current);return n.current={state:e,props:r},t},t)}}},withEffect=createWithEffect(React.useEffect),withLayoutEffect=createWithEffect(React.useLayoutEffect),withStateHandlers=function(r,i){var o=isFunction(r)?function(t,e){return function(){return r(t,e)}}:function(){return r},u=new WeakMap;return function(t,e){var r=_slicedToArray(React.useState(o(t,e)),2),a=r[0],c=r[1];u.has(c)||function(){var r={state:a,props:e,actionHandlers:{}};u.set(c,r);for(var t=function(){var t=_slicedToArray(o[n],2),e=t[0],i=t[1];r.actionHandlers[e]=function(){for(var t=u.get(c),e=t.state,r=t.props,n=arguments.length,o=new Array(n),a=0;a<n;a++)o[a]=arguments[a];!function(t){var o=u.get(c).state;Object.entries(t).some(function(t){var e=_slicedToArray(t,2),r=e[0],n=e[1];return o[r]!==n})&&c(_objectSpread({},o,t))}(i({args:o,state:e,props:r}))}},n=0,o=Object.entries(i);n<o.length;n++)t()}();var n=u.get(c);return n.state=a,n.props=e,_objectSpread({},a,n.actionHandlers)}},withAsyncEffect=function(t){function e(){c=!1}var c=!1,r=_objectSpread({dataName:"data"},t),u=r.asyncAction,n=r.disposeAction,f=r.dataName,s=r.deps,p=isFunction(n)?function(){e(),n()}:e;return function(r,n){var t,o=React.useRef({state:r,props:n}),e=_slicedToArray(React.useState((_defineProperty(t={loading:!0},f,null),_defineProperty(t,"error",null),t)),2),a=e[0],i=e[1];return React.useEffect(function(){var t;c&&i((_defineProperty(t={loading:!0},f,a[f]),_defineProperty(t,"error",null),t));c=!0;var e=u(r,n,o.current);if(o.current={state:r,props:n},!isPromiseLike(e))throw Error("withAsyncEffect expects Promise, got a: ".concat(getInternalCtor(e)));return e.then(function(t){var e;i((_defineProperty(e={loading:!1},f,t),_defineProperty(e,"error",null),e))},function(t){var e;i((_defineProperty(e={loading:!1},f,a[f]),_defineProperty(e,"error",t),e))}),p},getDeps(_objectSpread({},r,n),s)),a}},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,a=getDeps(_objectSpread({},r,n),t.deps||e);return React.useMemo(function(){return o(r,n)},a)},t);return function(t,e){return n(r,t,e)}},withMemo=function(n,o,a){return function(t,e){var r=React.useMemo(function(){return o(t,e)},getDeps(_objectSpread({},t,e),a));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,a=e.stateName,i=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={},a,r),_defineProperty(t,i,n),t}},withState=function(i,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],a=n[1];return _defineProperty(r={},i,o),_defineProperty(r,c,a),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.3.2",
"version": "1.3.3",
"name": "react-hooks-combine",

@@ -4,0 +4,0 @@ "description": "React hooks powered, recompose like utility belt for ladies and gentlemen.",

@@ -14,5 +14,3 @@ # React hooks combine

## Documentation
The documentation is divided into several sections:
- [API Reference](/docs/api-reference.md)
- [~~How it works~~ TBD](/docs/explanation.md)
Documentation can be found here: [API Reference](/docs/api-reference.md)

@@ -19,0 +17,0 @@ You can improve it by sending pull requests to this repository.

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc