From: Ben Beltran Date: Sat, 21 Apr 2018 08:11:47 +0000 (-0500) Subject: Yields nodeCollection instead of nodes array X-Git-Tag: 2.1.0^2~6 X-Git-Url: https://git.r.bdr.sh/rbdr/serpentity/commitdiff_plain/17e4efc7eeb88d7764582bea124c71989fe1f1cb?hp=4cee919d916319262296529f7a9b9857380aad52 Yields nodeCollection instead of nodes array --- diff --git a/lib/serpentity.js b/lib/serpentity.js index 0d932ac..60fb23c 100644 --- a/lib/serpentity.js +++ b/lib/serpentity.js @@ -223,7 +223,7 @@ const Serpentity = class Serpentity { nodeCollection.add(entity); } - return nodeCollection.nodes; + return nodeCollection; } /* diff --git a/lib/serpentity/node_collection.js b/lib/serpentity/node_collection.js index 73998b1..7c2c627 100644 --- a/lib/serpentity/node_collection.js +++ b/lib/serpentity/node_collection.js @@ -93,4 +93,13 @@ const NodeCollection = class NodeCollection extends Events { } }; + +/* + * Make the node collection iterable without returning the array directly + */ +NodeCollection.prototype[Symbol.iterator] = function * () { + + yield* this.nodes; +}; + module.exports = NodeCollection;