nano-tree

1.0.1 • Public • Published

Gitter NPM version Build status Test coverage Dependency Status License Downloads

nano-tree

The library for very convenient creating of objects hierarhies.

Example

var nano = require('nano-tree');
 
function MenuPage(type, id) {
    nano.Node.call(this, type, id);
}
 
MenuPage.prototype = {
    toString: function () { return this.type+(this.id.charAt(0) !== '$' ? '#'+this.id : ''); }
};
 
function MenuGroup(type, id) {
    nano.Group.call(this, type, id);
};
 
MenuGroup.prototype = {
    toString: function () {
        var cs = this.children;
        return MenuPage.prototype.toString.call(this)+':['+Object.keys(cs).map(function (key) {
            return cs[key].toString();
        }).join(',')+']';
    }
};
 
nano.Node.expand(MenuPage);
nano.Group.expand(MenuGroup);
 
MenuGroup.register('page', MenuPage);
MenuGroup.register('group', MenuGroup);
 
var menu = 
(new MenuGroup('menu', 'root'))
    .group('internet')
        .page('wan')
        .up
    .group('system')
        .page('options')
        .page('reboot')
        .page('options') // test of duplicated id
        .up
    .group()
        .page()
        .up;
 
assert.strictEqual('menu#root:[group#internet:[page#wan],group#system:[page#reboot,page#options],group:[page]]', menu.toString());
 

Readme

Keywords

Package Sidebar

Install

npm i nano-tree

Weekly Downloads

3

Version

1.0.1

License

MIT

Last publish

Collaborators

  • holixus