From: Ben Beltran Date: Sat, 21 Apr 2018 07:49:42 +0000 (-0500) Subject: Emit events X-Git-Tag: 2.1.0^2~10 X-Git-Url: https://git.r.bdr.sh/rbdr/serpentity/commitdiff_plain/4908bfb50681ed410dc557005033959457e05d2f?ds=inline;hp=--cc Emit events --- 4908bfb50681ed410dc557005033959457e05d2f diff --git a/lib/serpentity/node_collection.js b/lib/serpentity/node_collection.js index 8da41da..bb66a8d 100644 --- a/lib/serpentity/node_collection.js +++ b/lib/serpentity/node_collection.js @@ -1,5 +1,7 @@ 'use strict'; +const Events = require('events'); + /* * Node Collections contain nodes, in order to keep the lists of nodes * that belong to each type. @@ -8,7 +10,7 @@ * instances of that class. */ -const NodeCollection = class NodeCollection { +const NodeCollection = class NodeCollection extends Events { constructor(config) { @@ -39,6 +41,7 @@ const NodeCollection = class NodeCollection { } this.nodes.push(node); + this.emit('nodeAdded', { node }); return true; } @@ -65,6 +68,7 @@ const NodeCollection = class NodeCollection { if (found) { this.nodes.splice(foundIndex, 1); + this.emit('nodeRemoved', { node }); } return found;