-'use strict';
-
-const Events = require('events');
-
/*
* Node Collections contain nodes, in order to keep the lists of nodes
* that belong to each type.
* instances of that class.
*/
-const NodeCollection = class NodeCollection extends Events {
+export class NodeCollection extends EventTarget {
constructor(config) {
}
this.nodes.push(node);
- this.emit('nodeAdded', { node });
+ const event = new Event('nodeAdded');
+ event.node = node;
+ this.dispatchEvent(event);
return true;
}
if (found) {
this.nodes.splice(foundIndex, 1);
- this.emit('nodeRemoved', { node: foundNode });
+ const event = new Event('nodeRemoved');
+ event.node = foundNode;
+ this.dispatchEvent(event);
}
return found;
*/
_entityExists(entity) {
- let found = false;
-
- for (const node of this.nodes) {
- if (node.entity === entity) {
- found = true;
- }
- }
-
- return found;
+ return this.nodes.some((node) => node.entity === entity);
}
-};
+}
/*
yield* this.nodes;
};
-
-module.exports = NodeCollection;