Merge pull request #281 from matrix-org/rav/velociraptor_fixes

Various fixes to the velociraptor
pull/21833/head
Richard van der Hoff 2016-04-21 14:25:07 +01:00
commit 380b991d16
3 changed files with 32 additions and 17 deletions

View File

@ -49,6 +49,7 @@
"babel": "^5.8.23",
"babel-core": "^5.8.38",
"babel-loader": "^5.4.0",
"babel-polyfill": "^6.5.0",
"expect": "^1.16.0",
"json-loader": "^0.5.3",
"karma": "^0.13.22",

View File

@ -13,25 +13,30 @@ module.exports = React.createClass({
displayName: 'Velociraptor',
propTypes: {
children: React.PropTypes.array,
// either a list of child nodes, or a single child.
children: React.PropTypes.any,
// optional transition information for changing existing children
transition: React.PropTypes.object,
container: React.PropTypes.string
},
componentWillMount: function() {
this.children = {};
this.nodes = {};
var self = this;
React.Children.map(this.props.children, function(c) {
self.children[c.key] = c;
});
this._updateChildren(this.props.children);
},
componentWillReceiveProps: function(nextProps) {
this._updateChildren(nextProps.children);
},
/**
* update `this.children` according to the new list of children given
*/
_updateChildren: function(newChildren) {
var self = this;
var oldChildren = this.children;
var oldChildren = this.children || {};
this.children = {};
React.Children.map(nextProps.children, function(c) {
React.Children.toArray(newChildren).forEach(function(c) {
if (oldChildren[c.key]) {
var old = oldChildren[c.key];
var oldNode = ReactDom.findDOMNode(self.nodes[old.key]);
@ -92,22 +97,23 @@ module.exports = React.createClass({
//console.log("start: "+JSON.stringify(startStyles[i]));
}
// and then we animate to the resting state
Velocity(domNode, node.props._restingStyle, transitionOpts[i-1]);
Velocity(domNode, node.props._restingStyle,
transitionOpts[i-1])
.then(() => {
// once we've reached the resting state, hide the element if
// appropriate
domNode.style.visibility = node.props._restingStyle.visibility;
});
//console.log("enter: "+JSON.stringify(node.props._restingStyle));
}
this.nodes[k] = node;
},
render: function() {
var self = this;
var childList = Object.keys(this.children).map(function(k) {
return React.cloneElement(self.children[k], {
ref: self.collectNode.bind(self, self.children[k].key)
});
});
return (
<span>
{childList}
{Object.values(this.children)}
</span>
);
},

View File

@ -5,6 +5,14 @@
* application to provide
*/
/* this is a convenient place to ensure we load the compatibility libraries we expect our
* app to provide
*/
// for ES6 stuff like startsWith() and Object.values() that babel doesn't do by
// default
require('babel-polyfill');
var sdk = require("../src/index");
var skin = require('../src/component-index.js');