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
- Host: GitHub
- URL: https://github.com/fantasyui-com/graft-tree
- Owner: fantasyui-com
- License: gpl-3.0
- Created: 2018-07-05T14:02:09.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2021-11-03T19:16:08.000Z (over 4 years ago)
- Last Synced: 2025-02-11T13:08:08.983Z (over 1 year ago)
- Language: JavaScript
- Size: 17.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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');
```