react-tree-walker
Advanced tools
Comparing version 4.0.2 to 4.1.0
@@ -116,2 +116,13 @@ 'use strict'; | ||
if (currentElement.type) { | ||
if (currentElement.type._context) { | ||
// eslint-disable-next-line no-param-reassign | ||
currentElement.type._context._currentValue = currentElement.props.value; | ||
} | ||
if (currentElement.type.Provider && currentElement.type.Consumer) { | ||
var el = currentElement.props.children(currentElement.type.Provider._context._currentValue); | ||
return recursive(el, currentContext); | ||
} | ||
} | ||
if (isReactElement(currentElement)) { | ||
@@ -118,0 +129,0 @@ return new Promise(function (innerResolve) { |
@@ -1,2 +0,2 @@ | ||
"use strict";var defaultOptions={componentWillUnmount:!1},pReduce=function(e,n,t){return new Promise(function(r,o){var i=e[Symbol.iterator](),u=0;!function e(t){var c=i.next();c.done?r(t):Promise.all([t,c.value]).then(function(t){e(n(t[0],t[1],u++))}).catch(o)}(t)})},pMapSeries=function(e,n){var t=[];return pReduce(e,function(e,r,o){return Promise.resolve(n(r,o)).then(function(e){t.push(e)})}).then(function(){return t})},ensureChild=function e(n){return n&&"function"==typeof n.render?e(n.render()):n},getChildren=function(e){return e.props&&e.props.children?e.props.children:e.children?e.children:void 0},getType=function(e){return e.type||e.nodeName},getProps=function(e){return e.props||e.attributes},isReactElement=function(e){return!!getType(e)},isClassComponent=function(e){return e.prototype&&(e.prototype.render||e.prototype.isReactComponent||e.prototype.isPureReactComponent)},providesChildContext=function(e){return!!e.getChildContext};function reactTreeWalker(e,n,t){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:defaultOptions;return new Promise(function(o,i){var u=function(){try{return n.apply(void 0,arguments)}catch(e){i(e)}};(function e(n,t){return Array.isArray(n)?Promise.all(n.map(function(n){return e(n,t)})):n?"string"==typeof n||"number"==typeof n?(u(n,null,t),Promise.resolve()):isReactElement(n)?new Promise(function(o){var c=function(t,r,c,s){return Promise.resolve(u(n,r,c,s)).then(function(n){if(!1!==n){var r=t(),u=ensureChild(r);if(u)return Array.isArray(u)?pMapSeries(u,function(n){return n?e(n,s):Promise.resolve()}).then(o,i).catch(i):e(u,s).then(o,i).catch(i)}}).catch(i)};if("function"==typeof getType(n)){var s=getType(n),p=Object.assign({},s.defaultProps,getProps(n),{children:getChildren(n)});if(isClassComponent(s)){var l=new s(p,t);l.props=l.props||p,l.context=l.context||t,l.state=l.state||null,l.setState=function(e){"function"==typeof e&&(e=e(l.state,l.props,l.context)),l.state=Object.assign({},l.state,e)},l.componentWillMount&&l.componentWillMount();var a=providesChildContext(l)?Object.assign({},t,l.getChildContext()):t;c(function(){return l.render(l.props,l.state)},l,t,a).then(function(){r.componentWillUnmount&&l.componentWillUnmount&&l.componentWillUnmount()}).then(o)}else c(function(){return s(p,t)},null,t,t).then(o)}else c(function(){return getChildren(n)},null,t,t).then(o)}):n.containerInfo&&n.children&&n.children.props&&Array.isArray(n.children.props.children)?Promise.all(n.children.props.children.map(function(n){return e(n,t)})):Promise.resolve():Promise.resolve()})(e,t).then(o,i)})}module.exports=reactTreeWalker; | ||
"use strict";var defaultOptions={componentWillUnmount:!1},pReduce=function(e,n,t){return new Promise(function(r,o){var i=e[Symbol.iterator](),u=0;!function e(t){var c=i.next();c.done?r(t):Promise.all([t,c.value]).then(function(t){e(n(t[0],t[1],u++))}).catch(o)}(t)})},pMapSeries=function(e,n){var t=[];return pReduce(e,function(e,r,o){return Promise.resolve(n(r,o)).then(function(e){t.push(e)})}).then(function(){return t})},ensureChild=function e(n){return n&&"function"==typeof n.render?e(n.render()):n},getChildren=function(e){return e.props&&e.props.children?e.props.children:e.children?e.children:void 0},getType=function(e){return e.type||e.nodeName},getProps=function(e){return e.props||e.attributes},isReactElement=function(e){return!!getType(e)},isClassComponent=function(e){return e.prototype&&(e.prototype.render||e.prototype.isReactComponent||e.prototype.isPureReactComponent)},providesChildContext=function(e){return!!e.getChildContext};function reactTreeWalker(e,n,t){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:defaultOptions;return new Promise(function(o,i){var u=function(){try{return n.apply(void 0,arguments)}catch(e){i(e)}};(function e(n,t){if(Array.isArray(n))return Promise.all(n.map(function(n){return e(n,t)}));if(!n)return Promise.resolve();if("string"==typeof n||"number"==typeof n)return u(n,null,t),Promise.resolve();if(n.type&&(n.type._context&&(n.type._context._currentValue=n.props.value),n.type.Provider&&n.type.Consumer)){var o=n.props.children(n.type.Provider._context._currentValue);return e(o,t)}return isReactElement(n)?new Promise(function(o){var c=function(t,r,c,p){return Promise.resolve(u(n,r,c,p)).then(function(n){if(!1!==n){var r=t(),u=ensureChild(r);if(u)return Array.isArray(u)?pMapSeries(u,function(n){return n?e(n,p):Promise.resolve()}).then(o,i).catch(i):e(u,p).then(o,i).catch(i)}}).catch(i)};if("function"==typeof getType(n)){var p=getType(n),s=Object.assign({},p.defaultProps,getProps(n),{children:getChildren(n)});if(isClassComponent(p)){var l=new p(s,t);l.props=l.props||s,l.context=l.context||t,l.state=l.state||null,l.setState=function(e){"function"==typeof e&&(e=e(l.state,l.props,l.context)),l.state=Object.assign({},l.state,e)},l.componentWillMount&&l.componentWillMount();var a=providesChildContext(l)?Object.assign({},t,l.getChildContext()):t;c(function(){return l.render(l.props,l.state)},l,t,a).then(function(){r.componentWillUnmount&&l.componentWillUnmount&&l.componentWillUnmount()}).then(o)}else c(function(){return p(s,t)},null,t,t).then(o)}else c(function(){return getChildren(n)},null,t,t).then(o)}):n.containerInfo&&n.children&&n.children.props&&Array.isArray(n.children.props.children)?Promise.all(n.children.props.children.map(function(n){return e(n,t)})):Promise.resolve()})(e,t).then(o,i)})}module.exports=reactTreeWalker; | ||
//# sourceMappingURL=react-tree-walker.min.js.map |
{ | ||
"name": "react-tree-walker", | ||
"version": "4.0.2", | ||
"version": "4.1.0", | ||
"description": | ||
@@ -18,4 +18,3 @@ "Walk a React element tree, executing a provided function against each node.", | ||
"build": "node ./tools/scripts/build.js", | ||
"clean": | ||
"rimraf ./commonjs && rimraf ./umd && rimraf ./coverage && rimraf ./umd", | ||
"clean": "rimraf ./dist && rimraf ./coverage", | ||
"lint": "eslint src", | ||
@@ -65,3 +64,3 @@ "precommit": "lint-staged && npm run test", | ||
"ramda": "^0.25.0", | ||
"react": "^16.0.0", | ||
"react": "^16.4.0", | ||
"react-addons-test-utils": "^15.6.2", | ||
@@ -68,0 +67,0 @@ "react-dom": "^16.0.0", |
@@ -41,3 +41,3 @@ # react-tree-walker 🌲 | ||
// data, or do whatever "bootstrapping" you desire. | ||
return Promise.resove(this.props.id) | ||
return Promise.resolve(this.props.id) | ||
} | ||
@@ -116,3 +116,3 @@ | ||
The API is very simple at the moment, only exposing a single function, which you can import as follows | ||
The API is very simple at the moment, only exposing a single function. We will describe the API of the `reactTreeWalker` function below as well as the API for the `visitor` function that `reactTreeWalker` expects as a parameter. | ||
@@ -125,3 +125,3 @@ --- | ||
``` | ||
```javascript | ||
const reactTreeWalker = require('react-tree-walker') | ||
@@ -132,7 +132,7 @@ ``` | ||
``` | ||
```javascript | ||
import reactTreeWalker from 'react-tree-walker' | ||
``` | ||
**Paramaters** | ||
**Parameters** | ||
@@ -139,0 +139,0 @@ * **tree** (React/Preact element, _required_) |
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
53686
252