Comparing version 1.0.0 to 1.0.1
58
box.js
@@ -9,13 +9,21 @@ var React = require('react'); | ||
return { | ||
cache: [] | ||
cache: [], | ||
hash: generateHashFunction(this.props.hashFunction) | ||
}; | ||
}, | ||
getDefaultProps: function() { | ||
return { | ||
hashFunction: function(child) { | ||
return JSON.stringify({ | ||
key: child.key, | ||
props: child.props | ||
}); | ||
} | ||
}; | ||
}, | ||
componentDidMount: function() { | ||
this.readChildren(this.props.children); | ||
}, | ||
componentWillReceiveProps: function(p) { | ||
var cache = this.state.cache; | ||
React.Children.forEach(p.children, function(child) { | ||
cache[signature(child)] = child; | ||
}); | ||
this.setState({ cache: cache }); | ||
this.readChildren(p.children); | ||
}, | ||
@@ -30,6 +38,15 @@ render: function() { | ||
}, | ||
readChildren: function(children) { | ||
var cache = this.state.cache; | ||
React.Children.forEach(children, function(child) { | ||
cache[this.state.hash(child)] = child; | ||
}, this); | ||
this.setState({ cache: cache }); | ||
}, | ||
visibility: function(key) { | ||
var c = React.Children.map(this.props.children, function(child) { | ||
return key === signature(child); | ||
}); | ||
return key === this.state.hash(child); | ||
}, this); | ||
@@ -40,16 +57,15 @@ return c ? values(c).some(isTrue) : false; | ||
var ref = {}; | ||
var index = 0; | ||
function generateHashFunction(hashFunction) { | ||
var ref = {}; | ||
var index = 0; | ||
function signature(child) { | ||
var key = JSON.stringify({ | ||
key: child.key, | ||
props: child.props | ||
}); | ||
return function(child) { | ||
var key = hashFunction(child); | ||
if (!ref[key]) { | ||
ref[key] = String(++index); | ||
} | ||
if (!ref[key]) { | ||
ref[key] = String(++index); | ||
} | ||
return ref[key]; | ||
return ref[key]; | ||
}; | ||
} | ||
@@ -56,0 +72,0 @@ |
{ | ||
"name": "react-box", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Wraps repeatedly rerendered components preserving their nodes in real DOM to reduce paints", | ||
@@ -5,0 +5,0 @@ "main": "box.js", |
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
6734
115