Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
cheton committed Jun 2, 2016
2 parents 5a3e091 + f2bc4fc commit 7b03a7e
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 30 deletions.
41 changes: 28 additions & 13 deletions dist/infinite-tree.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! infinite-tree v1.3.0 | (c) 2016 Cheton Wu <[email protected]> | MIT | https://github.com/cheton/infinite-tree */
/*! infinite-tree v1.3.1 | (c) 2016 Cheton Wu <[email protected]> | MIT | https://github.com/cheton/infinite-tree */
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
Expand Down Expand Up @@ -124,6 +124,20 @@ return /******/ (function(modules) { // webpackBootstrap
return true;
};

var createRootNode = function createRootNode() {
return new _flattree.Node({
parent: null,
children: [],
state: {
depth: -1,
open: true, // always open
path: '',
prefixMask: '',
total: 0
}
});
};

var InfiniteTree = function (_events$EventEmitter) {
_inherits(InfiniteTree, _events$EventEmitter);

Expand All @@ -150,7 +164,7 @@ return /******/ (function(modules) { // webpackBootstrap
};
_this.state = {
openNodes: [],
rootNode: null,
rootNode: createRootNode(),
selectedNode: null
};
_this.clusterize = null;
Expand Down Expand Up @@ -590,7 +604,7 @@ return /******/ (function(modules) { // webpackBootstrap
this.nodes = [];
this.rows = [];
this.state.openNodes = [];
this.state.rootNode = null;
this.state.rootNode = createRootNode();
this.state.selectedNode = null;
};
// Closes a node to hide its children.
Expand Down Expand Up @@ -809,7 +823,9 @@ return /******/ (function(modules) { // webpackBootstrap
this.state.openNodes = this.nodes.filter(function (node) {
return node.hasChildren() && node.state.open;
});
this.state.rootNode = function () {
this.state.selectedNode = null;

var rootNode = function () {
var node = arguments.length <= 0 || arguments[0] === undefined ? null : arguments[0];

// Finding the root node
Expand All @@ -818,16 +834,15 @@ return /******/ (function(modules) { // webpackBootstrap
}
return node;
}(this.nodes.length > 0 ? this.nodes[0] : null);
this.state.selectedNode = null;

if (this.state.rootNode) {
// Update the lookup table with newly added nodes
this.flattenChildNodes(this.state.rootNode).forEach(function (node) {
if (node.id !== undefined) {
_this4.nodeTable.set(node.id, node);
}
});
}
this.state.rootNode = rootNode || createRootNode(); // Create a new root node if rootNode is null

// Update the lookup table with newly added nodes
this.flattenChildNodes(this.state.rootNode).forEach(function (node) {
if (node.id !== undefined) {
_this4.nodeTable.set(node.id, node);
}
});

// Update rows
this.rows = this.nodes.map(function (node) {
Expand Down
6 changes: 3 additions & 3 deletions dist/infinite-tree.min.js

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions examples/classic/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,13 @@ const load = () => {
}
};

window.examples = {
...window.examples,
classic: {
tree: tree
}
};

export {
load
}
7 changes: 7 additions & 0 deletions examples/default/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,13 @@ const load = () => {
}
};

window.examples = {
...window.examples,
default: {
tree: tree
}
};

export {
load
}
7 changes: 7 additions & 0 deletions examples/filebrowser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ const load = () => {
setHeaderWidth();
};

window.examples = {
...window.examples,
filebrowser: {
tree: tree
}
};

export {
load
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "infinite-tree",
"version": "1.3.0",
"version": "1.3.1",
"description": "A browser-ready tree library that can efficiently display a large amount of data using infinite scrolling.",
"homepage": "https://github.com/cheton/infinite-tree",
"main": "lib/index.js",
Expand Down Expand Up @@ -36,7 +36,7 @@
],
"dependencies": {
"clusterize.js": "^0.16.0",
"flattree": "^0.8.2"
"flattree": "^0.9.0"
},
"devDependencies": {
"babel-cli": "^6.8.0",
Expand Down
37 changes: 25 additions & 12 deletions src/infinite-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ const ensureNodeInstance = (node) => {
return true;
};

const createRootNode = () => new Node({
parent: null,
children: [],
state: {
depth: -1,
open: true, // always open
path: '',
prefixMask: '',
total: 0
}
});

class InfiniteTree extends events.EventEmitter {
options = {
autoOpen: false,
Expand All @@ -50,7 +62,7 @@ class InfiniteTree extends events.EventEmitter {
};
state = {
openNodes: [],
rootNode: null,
rootNode: createRootNode(),
selectedNode: null
};
clusterize = null;
Expand Down Expand Up @@ -474,7 +486,7 @@ class InfiniteTree extends events.EventEmitter {
this.nodes = [];
this.rows = [];
this.state.openNodes = [];
this.state.rootNode = null;
this.state.rootNode = createRootNode();
this.state.selectedNode = null;
}
// Closes a node to hide its children.
Expand Down Expand Up @@ -661,23 +673,24 @@ class InfiniteTree extends events.EventEmitter {
this.nodeTable.clear();

this.state.openNodes = this.nodes.filter((node) => (node.hasChildren() && node.state.open));
this.state.rootNode = ((node = null) => {
this.state.selectedNode = null;

const rootNode = ((node = null) => {
// Finding the root node
while (node && node.parent !== null) {
node = node.parent;
}
return node;
})((this.nodes.length > 0) ? this.nodes[0] : null);
this.state.selectedNode = null;

if (this.state.rootNode) {
// Update the lookup table with newly added nodes
this.flattenChildNodes(this.state.rootNode).forEach((node) => {
if (node.id !== undefined) {
this.nodeTable.set(node.id, node);
}
});
}
this.state.rootNode = rootNode || createRootNode(); // Create a new root node if rootNode is null

// Update the lookup table with newly added nodes
this.flattenChildNodes(this.state.rootNode).forEach((node) => {
if (node.id !== undefined) {
this.nodeTable.set(node.id, node);
}
});

// Update rows
this.rows = this.nodes.map(node => this.options.rowRenderer(node, this.options));
Expand Down

0 comments on commit 7b03a7e

Please sign in to comment.