Skip to content

evanrs/thin-tree

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

75 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

thin-tree thin-tree build status.

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

About

Thin tree is a tool for building recursive structures

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published