react-tree-walker
Advanced tools
Comparing version 4.2.0 to 4.3.0
@@ -12,6 +12,9 @@ 'use strict'; | ||
componentWillUnmount: false | ||
}; | ||
// Lifted from https://github.com/sindresorhus/p-reduce | ||
// Thanks @sindresorhus! 🙏 | ||
};var pReduce = function pReduce(iterable, reducer, initVal) { | ||
var forwardRefSymbol = Symbol.for('react.forward_ref'); | ||
// Lifted from https://github.com/sindresorhus/p-reduce | ||
// Thanks @sindresorhus! 🙏 | ||
var pReduce = function pReduce(iterable, reducer, initVal) { | ||
return new Promise(function (resolve, reject) { | ||
@@ -80,2 +83,6 @@ var iterator = iterable[Symbol.iterator](); | ||
var isForwardRef = function isForwardRef(Comp) { | ||
return Comp.type && Comp.type.$$typeof === forwardRefSymbol; | ||
}; | ||
var providesChildContext = function providesChildContext(instance) { | ||
@@ -155,3 +162,3 @@ return !!instance.getChildContext; | ||
if (typeof getType(currentElement) === 'function') { | ||
if (typeof getType(currentElement) === 'function' || isForwardRef(currentElement)) { | ||
var Component = getType(currentElement); | ||
@@ -164,4 +171,7 @@ var props = Object.assign({}, Component.defaultProps, getProps(currentElement), | ||
}); | ||
if (isClassComponent(Component)) { | ||
if (isForwardRef(currentElement)) { | ||
visitCurrentElement(function () { | ||
return currentElement.type.render(props); | ||
}, null, currentContext, currentContext).then(innerResolve); | ||
} else if (isClassComponent(Component)) { | ||
// Class component | ||
@@ -168,0 +178,0 @@ var instance = new Component(props, currentContext); |
@@ -1,2 +0,2 @@ | ||
"use strict";var defaultOptions={componentWillUnmount:!1},pReduce=function(e,c,t){return new Promise(function(r,o){var i=e[Symbol.iterator](),u=0;!function t(e){var n=i.next();n.done?r(e):Promise.all([e,n.value]).then(function(e){t(c(e[0],e[1],u++))}).catch(o)}(t)})},pMapSeries=function(e,r){var o=[];return pReduce(e,function(e,t,n){return Promise.resolve(r(t,n)).then(function(e){o.push(e)})}).then(function(){return o})},ensureChild=function e(t){return t&&"function"==typeof t.render?e(t.render()):t},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(t,n,r){var f=3<arguments.length&&void 0!==arguments[3]?arguments[3]:defaultOptions;return new Promise(function(e,l){var a=function(){try{return n.apply(void 0,arguments)}catch(e){l(e)}};(function c(p,s){if(Array.isArray(p))return Promise.all(p.map(function(e){return c(e,s)}));if(!p)return Promise.resolve();if("string"==typeof p||"number"==typeof p)return a(p,null,s),Promise.resolve();if(p.type&&(p.type._context&&(p.type._context._currentValue=p.props.value),p.type.Provider&&p.type.Consumer)){var e=p.props.children(p.type.Provider._context._currentValue);return c(e,s)}return isReactElement(p)?new Promise(function(i){var e=function(r,e,t,o){return Promise.resolve(a(p,e,t,o)).then(function(e){if(!1!==e){var t=r(),n=ensureChild(t);if(n)return Array.isArray(n)?pMapSeries(n,function(e){return e?c(e,o):Promise.resolve()}).then(i,l).catch(l):c(n,o).then(i,l).catch(l)}}).catch(l)};if("function"==typeof getType(p)){var t=getType(p),n=Object.assign({},t.defaultProps,getProps(p),{children:getChildren(p)});if(isClassComponent(t)){var r=new t(n,s);if(Object.defineProperty(r,"props",{value:r.props||n}),r.context=r.context||s,r.state=r.state||null,r.setState=function(e){"function"==typeof e&&(e=e(r.state,r.props,r.context)),r.state=Object.assign({},r.state,e)},t.getDerivedStateFromProps){var o=t.getDerivedStateFromProps(r.props,r.state);null!==o&&(r.state=Object.assign({},r.state,o))}else r.UNSAFE_componentWillMount?r.UNSAFE_componentWillMount():r.componentWillMount&&r.componentWillMount();var u=providesChildContext(r)?Object.assign({},s,r.getChildContext()):s;e(function(){return r.render(r.props,r.state)},r,s,u).then(function(){f.componentWillUnmount&&r.componentWillUnmount&&r.componentWillUnmount()}).then(i)}else e(function(){return t(n,s)},null,s,s).then(i)}else e(function(){return getChildren(p)},null,s,s).then(i)}):p.containerInfo&&p.children&&p.children.props&&Array.isArray(p.children.props.children)?Promise.all(p.children.props.children.map(function(e){return c(e,s)})):Promise.resolve()})(t,r).then(e,l)})}module.exports=reactTreeWalker; | ||
"use strict";var defaultOptions={componentWillUnmount:!1},forwardRefSymbol=Symbol.for("react.forward_ref"),pReduce=function(e,p,t){return new Promise(function(r,o){var i=e[Symbol.iterator](),u=0;!function t(e){var n=i.next();n.done?r(e):Promise.all([e,n.value]).then(function(e){t(p(e[0],e[1],u++))}).catch(o)}(t)})},pMapSeries=function(e,r){var o=[];return pReduce(e,function(e,t,n){return Promise.resolve(r(t,n)).then(function(e){o.push(e)})}).then(function(){return o})},ensureChild=function e(t){return t&&"function"==typeof t.render?e(t.render()):t},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)},isForwardRef=function(e){return e.type&&e.type.$$typeof===forwardRefSymbol},providesChildContext=function(e){return!!e.getChildContext};function reactTreeWalker(t,n,r){var f=3<arguments.length&&void 0!==arguments[3]?arguments[3]:defaultOptions;return new Promise(function(e,l){var a=function(){try{return n.apply(void 0,arguments)}catch(e){l(e)}};(function p(s,c){if(Array.isArray(s))return Promise.all(s.map(function(e){return p(e,c)}));if(!s)return Promise.resolve();if("string"==typeof s||"number"==typeof s)return a(s,null,c),Promise.resolve();if(s.type&&(s.type._context&&(s.type._context._currentValue=s.props.value),s.type.Provider&&s.type.Consumer)){var e=s.props.children(s.type.Provider._context._currentValue);return p(e,c)}return isReactElement(s)?new Promise(function(i){var e=function(r,e,t,o){return Promise.resolve(a(s,e,t,o)).then(function(e){if(!1!==e){var t=r(),n=ensureChild(t);if(n)return Array.isArray(n)?pMapSeries(n,function(e){return e?p(e,o):Promise.resolve()}).then(i,l).catch(l):p(n,o).then(i,l).catch(l)}}).catch(l)};if("function"==typeof getType(s)||isForwardRef(s)){var t=getType(s),n=Object.assign({},t.defaultProps,getProps(s),{children:getChildren(s)});if(isForwardRef(s))e(function(){return s.type.render(n)},null,c,c).then(i);else if(isClassComponent(t)){var r=new t(n,c);if(Object.defineProperty(r,"props",{value:r.props||n}),r.context=r.context||c,r.state=r.state||null,r.setState=function(e){"function"==typeof e&&(e=e(r.state,r.props,r.context)),r.state=Object.assign({},r.state,e)},t.getDerivedStateFromProps){var o=t.getDerivedStateFromProps(r.props,r.state);null!==o&&(r.state=Object.assign({},r.state,o))}else r.UNSAFE_componentWillMount?r.UNSAFE_componentWillMount():r.componentWillMount&&r.componentWillMount();var u=providesChildContext(r)?Object.assign({},c,r.getChildContext()):c;e(function(){return r.render(r.props,r.state)},r,c,u).then(function(){f.componentWillUnmount&&r.componentWillUnmount&&r.componentWillUnmount()}).then(i)}else e(function(){return t(n,c)},null,c,c).then(i)}else e(function(){return getChildren(s)},null,c,c).then(i)}):s.containerInfo&&s.children&&s.children.props&&Array.isArray(s.children.props.children)?Promise.all(s.children.props.children.map(function(e){return p(e,c)})):Promise.resolve()})(t,r).then(e,l)})}module.exports=reactTreeWalker; | ||
//# sourceMappingURL=react-tree-walker.min.js.map |
{ | ||
"name": "react-tree-walker", | ||
"version": "4.2.0", | ||
"version": "4.3.0", | ||
"description": "Walk a React element tree, executing a provided function against each node.", | ||
@@ -42,5 +42,4 @@ "license": "MIT", | ||
"babel-core": "^6.26.3", | ||
"babel-eslint": "^8.2.5", | ||
"babel-jest": "^23.2.0", | ||
"babel-loader": "^7.1.5", | ||
"babel-eslint": "^8.2.6", | ||
"babel-jest": "^23.4.2", | ||
"babel-plugin-external-helpers": "^6.22.0", | ||
@@ -55,9 +54,9 @@ "babel-polyfill": "^6.26.0", | ||
"cross-env": "^5.2.0", | ||
"enzyme": "^3.1.0", | ||
"enzyme": "^3.4.1", | ||
"enzyme-to-json": "^3.3.4", | ||
"eslint": "^4.19.1", | ||
"eslint-config-airbnb": "^16.0.0", | ||
"eslint-config-airbnb": "^17.0.0", | ||
"eslint-config-prettier": "^2.6.0", | ||
"eslint-plugin-import": "^2.13.0", | ||
"eslint-plugin-jsx-a11y": "^6.1.0", | ||
"eslint-plugin-import": "^2.14.0", | ||
"eslint-plugin-jsx-a11y": "^6.1.1", | ||
"eslint-plugin-react": "^7.10.0", | ||
@@ -67,15 +66,15 @@ "gzip-size": "^5.0.0", | ||
"in-publish": "2.0.0", | ||
"jest": "^23.3.0", | ||
"lint-staged": "^7.2.0", | ||
"preact": "^8.2.9", | ||
"prettier": "^1.13.7", | ||
"jest": "^23.5.0", | ||
"lint-staged": "^7.2.2", | ||
"preact": "^8.3.0", | ||
"prettier": "^1.14.2", | ||
"pretty-bytes": "5.1.0", | ||
"prop-types": "^15.6.2", | ||
"ramda": "^0.25.0", | ||
"react": "^16.4.1", | ||
"react": "^16.4.2", | ||
"react-addons-test-utils": "^15.6.2", | ||
"react-dom": "^16.4.1", | ||
"react-dom": "^16.4.2", | ||
"readline-sync": "1.4.9", | ||
"rimraf": "^2.6.2", | ||
"rollup": "^0.62.0", | ||
"rollup": "^0.64.1", | ||
"rollup-plugin-babel": "^3.0.7", | ||
@@ -106,3 +105,5 @@ "rollup-plugin-uglify": "^4.0.0" | ||
"airbnb", | ||
"prettier" | ||
"prettier", | ||
"prettier/react", | ||
"prettier/standard" | ||
], | ||
@@ -115,2 +116,3 @@ "rules": { | ||
"no-underscore-dangle": 0, | ||
"react/destructuring-assignment": 0, | ||
"react/no-array-index-key": 0, | ||
@@ -117,0 +119,0 @@ "react/react-in-jsx-scope": 0, |
@@ -0,1 +1,12 @@ | ||
### Disclaimer | ||
This library does not operate in an idiomatic manner against React. It makes some assumptions about the internals of React and makes calls against Components directly. This is a risk as it likely to break with future releases of React, i.e. the upcoming Suspense release. | ||
Personally, I've found this library helpful in providing me with a solution for my server side rendering data fetching needs. That being said I very much look forward to being able to move over to Suspense as soon as it is stable and avoid having to use hacks/workarounds such as this library. | ||
Please consider carefully before adopting this library. If you are happy to take on the risk I would recommend you write an abstraction over it that will allow you to easily remove/replace it from your codebase with Suspense or another more idiomatic solution. | ||
---- | ||
# react-tree-walker 🌲 | ||
@@ -2,0 +13,0 @@ |
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
59448
40
272
236