1.0.1 • Published 2 years ago
nv-event-target-tree-patch-cli v1.0.1
nv-cli-event-tree-patch-cli
- cli tool, generate event-target class-template for nv-data-tree-csp-node AND nv-remote-tree
- USELESS for other people
install
- npm install nv-cli-event-tree-patch-cli -g
usage
Usage: nv_evt_tree_patch [options]
Options:
-e, --extends class EventTarget extends [clsname],default _Node
-i, --imports imports/require,default const {_Node} =require("nv-data-tree-csp-node");
-h, --help usage
example
# nv_evt_tree_patch -e _Node
const {_Node} =require("nv-data-tree-csp-node");
class EventTarget extends _Node {
////
['#recv'] = (src,msg,dst) => {} //dst is self
////
regis_$recv$(f) {
this['#recv'] = f
}
regis_$bubble_recv$(f) {
let _f = (src,msg,dst)=> {
f(src,msg,dst)
dst.send_to_parent(msg);
}
this['#recv'] = _f
}
regis_$capture_recv$(f) {
let _f = (src,msg,dst)=> {
f(src,msg,dst)
dst.send_to_children(msg);
}
this['#recv'] = _f
}
////
unicast(dst,msg) {dst['#recv'](this,msg,dst)}
multicast(dsts,msg) {
dsts.forEach(dst=>dst['#recv'](this,msg,dst))
}
////
send_to_parent(msg) {
return(this.unicast(this.$parent,msg))
}
////
send_to_children(msg) {
return(this.multicast(this.$children_,msg))
}
////
get $neighbors_() {
let arr = [this.$parent_,this.$rsib_,this.$lsib_];
arr = arr.filter(nd=>nd!==null);
arr=arr.concat(this.$children_);
return(arr)
}
send_to_neighbors(msg) {
return(this.multicast(this.$neighbors_,msg))
}
////
}
LICENSE
- ISC
1.0.1
2 years ago