Skip to content

Commit

Permalink
refactor(document): remove async.each() dependencies
Browse files Browse the repository at this point in the history
Re: #8073
  • Loading branch information
vkarpov15 committed Aug 16, 2019
1 parent 7c7b744 commit e98d2f7
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
25 changes: 25 additions & 0 deletions lib/helpers/each.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict';

module.exports = function each(arr, cb, done) {
if (arr.length === 0) {
return done();
}

let remaining = arr.length;
let err = null;
for (const v of arr) {
cb(v, function(_err) {
if (err != null) {
return;
}
if (_err != null) {
err = _err;
return done(err);
}

if (--remaining <= 0) {
return done();
}
});
}
};
11 changes: 2 additions & 9 deletions lib/plugins/removeSubdocs.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const each = require('async/each');
const each = require('../helpers/each');

/*!
* ignore
Expand All @@ -17,15 +17,8 @@ module.exports = function(schema) {
const _this = this;
const subdocs = this.$__getAllSubdocs();

if (!subdocs.length) {
next();
return;
}

each(subdocs, function(subdoc, cb) {
subdoc.$__remove(function(err) {
cb(err);
});
subdoc.$__remove(cb);
}, function(error) {
if (error) {
return _this.schema.s.hooks.execPost('remove:error', _this, [_this], { error: error }, function(error) {
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/saveSubdocs.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const each = require('async/each');
const each = require('../helpers/each');

/*!
* ignore
Expand Down
2 changes: 1 addition & 1 deletion test/document.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7903,7 +7903,7 @@ describe('document', function() {
}
}
});

const schema = new Schema({
items: [itemArray]
});
Expand Down

0 comments on commit e98d2f7

Please sign in to comment.