react-adopt
Advanced tools
Comparing version 0.3.3 to 0.4.0
@@ -13,6 +13,8 @@ /// <reference types="react" /> | ||
export declare type Mapper<RP, P> = Record<keyof RP, MapperValue<RP, P>>; | ||
export declare function adopt<RP = any, P = any>(mapper: Mapper<RP, P>): RPC<RP, P>; | ||
export declare type MapProps<RP> = (props: any) => RP; | ||
export declare function adopt<RP = any, P = any>(mapper: Mapper<RP, P>, mapProps?: MapProps<RP>): RPC<RP, P>; | ||
export declare type AdoptProps<RP, P> = P & { | ||
mapper: Mapper<RP, P>; | ||
children: ChildrenFn<RP>; | ||
mapProps?: MapProps<RP>; | ||
}; | ||
@@ -19,0 +21,0 @@ export declare class Adopt extends React.Component<AdoptProps<any, any>> { |
@@ -1,2 +0,2 @@ | ||
"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var React=_interopDefault(require("react")),extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])};function __extends(e,t){function r(){this.constructor=e}extendStatics(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}var __assign=Object.assign||function(e){for(var t,r=1,n=arguments.length;n>r;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e};function __rest(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&0>t.indexOf(n)&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);n.length>o;o++)0>t.indexOf(n[o])&&(r[n[o]]=e[n[o]])}return r}var values=Object.values,keys=Object.keys,assign=Object.assign;function omit(e,t){return keys(t).filter(function(t){return-1===e.indexOf(t)}).reduce(function(e,r){return __assign({},e,((n={})[r]=t[r],n));var n},{})}function prop(e,t){return t[e]}var isFn=function(e){return!!e&&"function"==typeof e},isValidRenderProp=function(e){return React.isValidElement(e)||isFn(e)};function adopt(e){if(!values(e).some(isValidRenderProp))throw Error("The render props object mapper just accept valid elements as value");return keys(e).reduce(function(t,r){return function(n){var o=n.children,i=__rest(n,["children"]);return React.createElement(t,__assign({},i),function(t){var n=prop(r,e),a=omit(keys(i),t),s=function(e){return isFn(o)?o(assign({},a,((t={})[r]=e,t))):null;var t};return isFn(n)?React.createElement(n,assign({},i,t,{render:s})):React.cloneElement(n,{},s)})}},function(e){var t=e.children,r=__rest(e,["children"]);return isFn(t)&&t(r)})}var Adopt=function(e){function t(t){var r=e.call(this,t)||this;return r.Composed=adopt(t.mapper),r}return __extends(t,e),t.prototype.render=function(){var e=this.props,t=__rest(e,["mapper"]);return React.createElement(this.Composed,__assign({},t))},t}(React.Component);exports.adopt=adopt,exports.Adopt=Adopt; | ||
"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var React=_interopDefault(require("react")),extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])};function __extends(e,t){function r(){this.constructor=e}extendStatics(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}var __assign=Object.assign||function(e){for(var t,r=1,n=arguments.length;n>r;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e};function __rest(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&0>t.indexOf(n)&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);n.length>o;o++)0>t.indexOf(n[o])&&(r[n[o]]=e[n[o]])}return r}var values=Object.values,keys=Object.keys,assign=Object.assign;function omit(e,t){return keys(t).filter(function(t){return-1===e.indexOf(t)}).reduce(function(e,r){return __assign({},e,((n={})[r]=t[r],n));var n},{})}function prop(e,t){return t[e]}var isFn=function(e){return!!e&&"function"==typeof e},isValidRenderProp=function(e){return React.isValidElement(e)||isFn(e)};function adopt(e,t){if(!values(e).some(isValidRenderProp))throw Error("The render props object mapper just accept valid elements as value");var r=keys(e);return r.reduce(function(n,o,i){return function(a){var s=a.children,c=__rest(a,["children"]);return React.createElement(n,__assign({},c),function(n){var a=prop(o,e),u=omit(keys(c),n),p=i===r.length-1,f=function(e){var r,n=assign({},u,((r={})[o]=e,r));return isFn(s)?s(t&&isFn(t)&&p?t(n):n):null};return isFn(a)?React.createElement(a,assign({},c,n,{render:f})):React.cloneElement(a,{},f)})}},function(e){var t=e.children,r=__rest(e,["children"]);return isFn(t)&&t(r)})}var Adopt=function(e){function t(t){var r=e.call(this,t)||this;return r.Composed=adopt(t.mapper,r.props.mapProps),r}return __extends(t,e),t.prototype.render=function(){var e=this.props,t=__rest(e,["mapper"]);return React.createElement(this.Composed,__assign({},t))},t}(React.Component);exports.adopt=adopt,exports.Adopt=Adopt; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
import React from"react";var extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])};function __extends(e,t){function r(){this.constructor=e}extendStatics(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}var __assign=Object.assign||function(e){for(var t,r=1,n=arguments.length;n>r;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e};function __rest(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&0>t.indexOf(n)&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);n.length>o;o++)0>t.indexOf(n[o])&&(r[n[o]]=e[n[o]])}return r}var values=Object.values,keys=Object.keys,assign=Object.assign;function omit(e,t){return keys(t).filter(function(t){return-1===e.indexOf(t)}).reduce(function(e,r){return __assign({},e,((n={})[r]=t[r],n));var n},{})}function prop(e,t){return t[e]}var isFn=function(e){return!!e&&"function"==typeof e},isValidRenderProp=function(e){return React.isValidElement(e)||isFn(e)};function adopt(e){if(!values(e).some(isValidRenderProp))throw Error("The render props object mapper just accept valid elements as value");return keys(e).reduce(function(t,r){return function(n){var o=n.children,i=__rest(n,["children"]);return React.createElement(t,__assign({},i),function(t){var n=prop(r,e),a=omit(keys(i),t),c=function(e){return isFn(o)?o(assign({},a,((t={})[r]=e,t))):null;var t};return isFn(n)?React.createElement(n,assign({},i,t,{render:c})):React.cloneElement(n,{},c)})}},function(e){var t=e.children,r=__rest(e,["children"]);return isFn(t)&&t(r)})}var Adopt=function(e){function t(t){var r=e.call(this,t)||this;return r.Composed=adopt(t.mapper),r}return __extends(t,e),t.prototype.render=function(){var e=this.props,t=__rest(e,["mapper"]);return React.createElement(this.Composed,__assign({},t))},t}(React.Component);export{adopt,Adopt}; | ||
import React from"react";var extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])};function __extends(e,t){function r(){this.constructor=e}extendStatics(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}var __assign=Object.assign||function(e){for(var t,r=1,n=arguments.length;n>r;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e};function __rest(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&0>t.indexOf(n)&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);n.length>o;o++)0>t.indexOf(n[o])&&(r[n[o]]=e[n[o]])}return r}var values=Object.values,keys=Object.keys,assign=Object.assign;function omit(e,t){return keys(t).filter(function(t){return-1===e.indexOf(t)}).reduce(function(e,r){return __assign({},e,((n={})[r]=t[r],n));var n},{})}function prop(e,t){return t[e]}var isFn=function(e){return!!e&&"function"==typeof e},isValidRenderProp=function(e){return React.isValidElement(e)||isFn(e)};function adopt(e,t){if(!values(e).some(isValidRenderProp))throw Error("The render props object mapper just accept valid elements as value");var r=keys(e);return r.reduce(function(n,o,i){return function(a){var s=a.children,c=__rest(a,["children"]);return React.createElement(n,__assign({},c),function(n){var a=prop(o,e),p=omit(keys(c),n),u=i===r.length-1,f=function(e){var r,n=assign({},p,((r={})[o]=e,r));return isFn(s)?s(t&&isFn(t)&&u?t(n):n):null};return isFn(a)?React.createElement(a,assign({},c,n,{render:f})):React.cloneElement(a,{},f)})}},function(e){var t=e.children,r=__rest(e,["children"]);return isFn(t)&&t(r)})}var Adopt=function(e){function t(t){var r=e.call(this,t)||this;return r.Composed=adopt(t.mapper,r.props.mapProps),r}return __extends(t,e),t.prototype.render=function(){var e=this.props,t=__rest(e,["mapper"]);return React.createElement(this.Composed,__assign({},t))},t}(React.Component);export{adopt,Adopt}; | ||
//# sourceMappingURL=index.m.js.map |
@@ -1,2 +0,2 @@ | ||
"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var React=_interopDefault(require("react")),extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])};function __extends(e,t){function r(){this.constructor=e}extendStatics(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}var __assign=Object.assign||function(e){for(var t,r=1,n=arguments.length;n>r;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e};function __rest(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&0>t.indexOf(n)&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);n.length>o;o++)0>t.indexOf(n[o])&&(r[n[o]]=e[n[o]])}return r}var values=Object.values,keys=Object.keys,assign=Object.assign;function omit(e,t){return keys(t).filter(function(t){return-1===e.indexOf(t)}).reduce(function(e,r){return __assign({},e,((n={})[r]=t[r],n));var n},{})}function prop(e,t){return t[e]}var isFn=function(e){return!!e&&"function"==typeof e},isValidRenderProp=function(e){return React.isValidElement(e)||isFn(e)};function adopt(e){if(!values(e).some(isValidRenderProp))throw Error("The render props object mapper just accept valid elements as value");return keys(e).reduce(function(t,r){return function(n){var o=n.children,i=__rest(n,["children"]);return React.createElement(t,__assign({},i),function(t){var n=prop(r,e),a=omit(keys(i),t),s=function(e){return isFn(o)?o(assign({},a,((t={})[r]=e,t))):null;var t};return isFn(n)?React.createElement(n,assign({},i,t,{render:s})):React.cloneElement(n,{},s)})}},function(e){var t=e.children,r=__rest(e,["children"]);return isFn(t)&&t(r)})}var Adopt=function(e){function t(t){var r=e.call(this,t)||this;return r.Composed=adopt(t.mapper),r}return __extends(t,e),t.prototype.render=function(){var e=this.props,t=__rest(e,["mapper"]);return React.createElement(this.Composed,__assign({},t))},t}(React.Component);exports.adopt=adopt,exports.Adopt=Adopt; | ||
"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var React=_interopDefault(require("react")),extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])};function __extends(e,t){function r(){this.constructor=e}extendStatics(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}var __assign=Object.assign||function(e){for(var t,r=1,n=arguments.length;n>r;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e};function __rest(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&0>t.indexOf(n)&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);n.length>o;o++)0>t.indexOf(n[o])&&(r[n[o]]=e[n[o]])}return r}var values=Object.values,keys=Object.keys,assign=Object.assign;function omit(e,t){return keys(t).filter(function(t){return-1===e.indexOf(t)}).reduce(function(e,r){return __assign({},e,((n={})[r]=t[r],n));var n},{})}function prop(e,t){return t[e]}var isFn=function(e){return!!e&&"function"==typeof e},isValidRenderProp=function(e){return React.isValidElement(e)||isFn(e)};function adopt(e,t){if(!values(e).some(isValidRenderProp))throw Error("The render props object mapper just accept valid elements as value");var r=keys(e);return r.reduce(function(n,o,i){return function(a){var s=a.children,c=__rest(a,["children"]);return React.createElement(n,__assign({},c),function(n){var a=prop(o,e),u=omit(keys(c),n),p=i===r.length-1,f=function(e){var r,n=assign({},u,((r={})[o]=e,r));return isFn(s)?s(t&&isFn(t)&&p?t(n):n):null};return isFn(a)?React.createElement(a,assign({},c,n,{render:f})):React.cloneElement(a,{},f)})}},function(e){var t=e.children,r=__rest(e,["children"]);return isFn(t)&&t(r)})}var Adopt=function(e){function t(t){var r=e.call(this,t)||this;return r.Composed=adopt(t.mapper,r.props.mapProps),r}return __extends(t,e),t.prototype.render=function(){var e=this.props,t=__rest(e,["mapper"]);return React.createElement(this.Composed,__assign({},t))},t}(React.Component);exports.adopt=adopt,exports.Adopt=Adopt; | ||
//# sourceMappingURL=index.umd.js.map |
{ | ||
"name": "react-adopt", | ||
"version": "0.3.3", | ||
"version": "0.4.0", | ||
"main": "dist/index.js", | ||
@@ -5,0 +5,0 @@ "umd:main": "dist/index.umd.js", |
@@ -17,2 +17,3 @@ :sunglasses: _**React Adopt -**_ Compose render props components like a pro | ||
- [Custom render and retrieving props from composed](#custom-render-and-retrieving-props-from-composed) | ||
- [Mapping props from mappers](#mapping-props-from-mappers) | ||
- [Leading with multiple params](#leading-with-multiple-params) | ||
@@ -137,2 +138,28 @@ - [Typescript support](#typescript-support) | ||
### Mapping props from mappers | ||
Sometimes get properties from your mappers can be kind a boring depending how nest is the result from each mapper. To easily avoid deep nested objects or combine your results, you can map the final results into a single object using de `mapProps` function as second parameter. | ||
```js | ||
import { adopt } from 'react-adopt' | ||
import { Value } from 'react-powerplug' | ||
const mapper = { | ||
greet: <Value initial="Hi" />, | ||
name: <Value initial="John" />, | ||
} | ||
const mapProps = ({ greet, name }) => ({ | ||
message: `${greet.value} ${name.value}`, | ||
}) | ||
const Composed = adopt(mapper, mapProps) | ||
const App = () => ( | ||
<Composed> | ||
{({ message }) => /* ... */} | ||
</Composed> | ||
) | ||
``` | ||
### Leading with multiple params | ||
@@ -139,0 +166,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
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
21940
53
250