Skip to content

Commit

Permalink
Use toArray instead of each to fix reordering bug
Browse files Browse the repository at this point in the history
  • Loading branch information
voltrevo committed Sep 22, 2015
1 parent 339bbea commit 5671a43
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
16 changes: 7 additions & 9 deletions lib/Collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ module.exports = function() {
};
};

collection.each = function(fn) {
var currElements = elements;
elements = [];

currElements.forEach(function(el) {
if (el.value) {
elements.push(el);
fn(el.value);
}
collection.toArray = function(fn) {
elements = elements.filter(function(element) {
return element.value !== undefined;
});

return elements.map(function(element) {
return element.value;
});
};

Expand Down
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = function(asyncParam) {

eventEmitter.emit = function(evt, value) {
async(function() {
events.get(evt).each(function(handler) {
events.get(evt).toArray().forEach(function(handler) {
handler(value);
});
});
Expand Down

0 comments on commit 5671a43

Please sign in to comment.