Skip to content

Very convenient objects hierarchies creation library.

License

Notifications You must be signed in to change notification settings

Holixus/nano-tree

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gitter NPM version Build status Test coverage Dependency Status License Downloads

nano-tree

Very convenient objects hierarchies creation library.

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.install('page', MenuPage);
MenuGroup.install('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());

About

Very convenient objects hierarchies creation library.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published