thin-tree

0.0.15-beta.1 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i thin-tree

Weekly Downloads

2

Version

0.0.15-beta.1

License

MIT

Last publish

Collaborators

  • evanrs