]> git.r.bdr.sh - rbdr/serpentity/blobdiff - lib/serpentity/node_collection.js
Trim gitignore
[rbdr/serpentity] / lib / serpentity / node_collection.js
index c603d6fd1c02f2748e38bcfac8e3a8e391e85a40..d2aa5994365417f381d8cc71b465e100778b3aa5 100644 (file)
@@ -1,7 +1,3 @@
-'use strict';
-
-const Events = require('events');
-
 /*
  * Node Collections contain nodes, in order to keep the lists of nodes
  * that belong to each type.
@@ -10,7 +6,7 @@ const Events = require('events');
  * instances of that class.
  */
 
-const NodeCollection = class NodeCollection extends Events {
+export class NodeCollection extends EventTarget {
 
   constructor(config) {
 
@@ -43,7 +39,9 @@ const NodeCollection = class NodeCollection extends Events {
       }
 
       this.nodes.push(node);
-      this.emit('nodeAdded', { node });
+      const event = new Event('nodeAdded');
+      event.node = node;
+      this.dispatchEvent(event);
 
       return true;
     }
@@ -72,7 +70,9 @@ const NodeCollection = class NodeCollection extends Events {
 
     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;
@@ -83,17 +83,9 @@ const NodeCollection = class NodeCollection extends Events {
    */
   _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);
   }
-};
+}
 
 
 /*
@@ -103,5 +95,3 @@ NodeCollection.prototype[Symbol.iterator] = function * () {
 
   yield* this.nodes;
 };
-
-module.exports = NodeCollection;