thin-tree
v0.0.15-beta.1
Published
Thin-tree helps build recursive tree structures.
Downloads
4
Readme
thin-tree
Thin tree helps build recursive structures.
Usage
var TT = require('thin-tree');
var eve = {
name: "Eve",
children: [
{
name: "Alice",
age: 7
},
{
name: "Bob",
age: 5
}
]
}
var eveTree = new TT.Find(eve);
expect('Alice' === eveTree.first().name).toBe(true);
expect('Alice' === eveTree.chain()
.where({parent: eveTree})
.first().value().name).toBe(true);
expect('Bob' === eveTree.find({age: 5}).name).toBe(true);
var SomeTree = TT.Find.extend({
prev: function() {
return !this.parent ? null
: this.parent.at(this.index() - 1);
},
next: function() {
return !this.parent ? null
: this.parent.at(this.index() + 1);
}
});
var someEveTree = new SomeTree(eve);
// Inheritance broken
expect(someEveTree.first().next().name).toBe('Bob'); // Fails