An open API service indexing awesome lists of open source software.

https://github.com/fantasyui-com/graft-tree

Tree Data Structure with Multiple Branch Flavors
https://github.com/fantasyui-com/graft-tree

Last synced: over 1 year ago
JSON representation

Tree Data Structure with Multiple Branch Flavors

Awesome Lists containing this project

README

          

# graft-tree
Tree Data Structure with Multiple Branch Flavors

```JavaScript

const Node = require('graft-tree');

const dungeon = new Node('Dungeon');

const lobby = dungeon.add('Lobby');

let roomNumber = 0;

let roomMaker = function(parent){
roomNumber = roomNumber +1;
const room = parent.add('Room #'+roomNumber);
room.on('object', (thing)=>{
if(thing == 'Bob'){
if(Math.random() > .5){
const newRoom = roomMaker(room);
console.log(room.location().join('/'), 'Bob made a new room ('+room.name +'->'+newRoom.name+')');
}else{
console.log(room.location().join('/'), 'Bob finished building');
}
}
});
return room;
}

roomMaker(lobby.add('Room #'+roomNumber)); // Create the first room
dungeon.pipe('Bob');
dungeon.pipe('Bob');
dungeon.pipe('Bob');
dungeon.pipe('Bob');

```