Skip to content

Commit

Permalink
Update generated nonJSX file to run tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
jverghese committed Feb 10, 2015
1 parent fb7171f commit 2808e27
Showing 1 changed file with 28 additions and 18 deletions.
46 changes: 28 additions & 18 deletions test/tree-browser.nonjsx.js
Expand Up @@ -47,24 +47,12 @@ var TreeBrowser = (function () {
* figure out which data point in the component state to toggle collapse.
* @param event The click event
*/
_handleTreeNodeClick: function(event) {
var target = $(event.target),
paths = [];
// If target is a tree node that's not a leaf, then perform collapse/expand.
if (target.hasClass(getCSSPrefix("node"))) {
while(target && !target.data("root")) { // while not root node
if (isEmpty(paths)) {
paths.unshift(target.text());
} else {
paths.unshift(target.prev().text());
}
// Traverse additional parent because react is adding an extraneous container.
target = target.parent().parent();
}
_handleClick: function(event) {
var paths = this.refs.treeRoot.getPathForContainedNode($(event.target));
if (paths != null) {
var clickedNode = this._findNodeFromPathArray(paths);
clickedNode.collapse = !clickedNode.collapse;
// Note: Perhaps react has a more concise of saying update with current state.
this.setState(this.state)
this.forceUpdate();
}
},
/**
Expand All @@ -86,8 +74,8 @@ var TreeBrowser = (function () {
render: function () {
return (
React.createElement("div", {className: getCSSPrefix("container")},
React.createElement("ul", {"data-root": "true", onClick: this._handleTreeNodeClick},
React.createElement(TreeNode, {data: this.state.data})
React.createElement("ul", {"data-root": "true", onClick: this._handleClick},
React.createElement(TreeNode, {ref: "treeRoot", data: this.state.data})
)
)
);
Expand All @@ -109,6 +97,27 @@ var TreeBrowser = (function () {
}
return node.collapse ? classes + " " + getCSSPrefix("collapsed") : classes;
},
/**
* Given an element in subtree, returns it's path from the root.
* @param target
* @returns {*}
*/
getPathForContainedNode: function(target) {
var paths = [];
if (target.hasClass(getCSSPrefix("node"))) {
while (target && !target.data("root")) { // while not root node
if (isEmpty(paths)) {
paths.unshift(target.text());
} else {
paths.unshift(target.prev().text());
}
// Traverse additional parent because react is adding an extraneous container.
target = target.parent().parent();
}
return paths;
}
return null;
},
render: function () {
var treeNodes = this.props.data.map(function (node) {
var nodeFragment = [
Expand Down Expand Up @@ -150,3 +159,4 @@ var TreeBrowser = (function () {
};

})();

0 comments on commit 2808e27

Please sign in to comment.