From 4908bfb50681ed410dc557005033959457e05d2f Mon Sep 17 00:00:00 2001 From: Ben Beltran Date: Sat, 21 Apr 2018 02:49:42 -0500 Subject: Emit events --- lib/serpentity/node_collection.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lib') 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; -- cgit