Skip to content

Commit

Permalink
Merge pull request #12471 from hasezoey/addNamesToFunctions
Browse files Browse the repository at this point in the history
Add more names to previously `anonymous` functions
  • Loading branch information
AbdelrahmanHafez committed Sep 26, 2022
2 parents a792dc3 + f58a320 commit 55112dc
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 17 deletions.
9 changes: 5 additions & 4 deletions lib/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -851,11 +851,12 @@ Document.prototype.update = function update() {

Document.prototype.updateOne = function updateOne(doc, options, callback) {
const query = this.constructor.updateOne({ _id: this._id }, doc, options);
query.pre(cb => {
this.constructor._middleware.execPre('updateOne', this, [this], cb);
const self = this;
query.pre(function queryPreUpdateOne(cb) {
self.constructor._middleware.execPre('updateOne', self, [self], cb);
});
query.post(cb => {
this.constructor._middleware.execPost('updateOne', this, [this], {}, cb);
query.post(function queryPostUpdateOne(cb) {
self.constructor._middleware.execPost('updateOne', self, [self], {}, cb);
});

if (this.$session() != null) {
Expand Down
2 changes: 1 addition & 1 deletion lib/helpers/timestamps/setupTimestamps.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module.exports = function setupTimestamps(schema, timestamps) {

schema.add(schemaAdditions);

schema.pre('save', function(next) {
schema.pre('save', function timestampsPreSave(next) {
const timestampOption = get(this, '$__.saveOptions.timestamps');
if (timestampOption === false) {
return next();
Expand Down
6 changes: 3 additions & 3 deletions lib/plugins/clearValidating.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
* ignore
*/

module.exports = function(schema) {
module.exports = function clearValidating(schema) {
// `this.$__.validating` tracks whether there are multiple validations running
// in parallel. We need to clear `this.$__.validating` before post hooks for gh-8597
const unshift = true;
schema.s.hooks.post('validate', false, function() {
schema.s.hooks.post('validate', false, function clearValidatingPostValidate() {
if (this.$isSubdocument) {
return;
}

this.$__.validating = null;
}, unshift);

schema.s.hooks.post('validate', false, function(error, res, next) {
schema.s.hooks.post('validate', false, function clearValidatingPostValidateError(error, res, next) {
if (this.$isSubdocument) {
next();
return;
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/removeSubdocs.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const each = require('../helpers/each');

module.exports = function removeSubdocs(schema) {
const unshift = true;
schema.s.hooks.pre('remove', false, function(next) {
schema.s.hooks.pre('remove', false, function removeSubDocsPreRemove(next) {
if (this.$isSubdocument) {
next();
return;
Expand Down
4 changes: 2 additions & 2 deletions lib/plugins/saveSubdocs.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const each = require('../helpers/each');

module.exports = function saveSubdocs(schema) {
const unshift = true;
schema.s.hooks.pre('save', false, function(next) {
schema.s.hooks.pre('save', false, function saveSubdocsPreSave(next) {
if (this.$isSubdocument) {
next();
return;
Expand Down Expand Up @@ -36,7 +36,7 @@ module.exports = function saveSubdocs(schema) {
});
}, null, unshift);

schema.s.hooks.post('save', function(doc, next) {
schema.s.hooks.post('save', function saveSubdocsPostSave(doc, next) {
if (this.$isSubdocument) {
next();
return;
Expand Down
8 changes: 4 additions & 4 deletions lib/plugins/sharding.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ const utils = require('../utils');
*/

module.exports = function shardingPlugin(schema) {
schema.post('init', function() {
schema.post('init', function shardingPluginPostInit() {
storeShard.call(this);
return this;
});
schema.pre('save', function(next) {
schema.pre('save', function shardingPluginPreSave(next) {
applyWhere.call(this);
next();
});
schema.pre('remove', function(next) {
schema.pre('remove', function shardingPluginPreRemove(next) {
applyWhere.call(this);
next();
});
schema.post('save', function() {
schema.post('save', function shardingPluginPostSave() {
storeShard.call(this);
});
};
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/trackTransaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const sessionNewDocuments = require('../helpers/symbols').sessionNewDocuments;
const utils = require('../utils');

module.exports = function trackTransaction(schema) {
schema.pre('save', function() {
schema.pre('save', function trackTransactionPreSave() {
const session = this.$session();
if (session == null) {
return;
Expand Down
2 changes: 1 addition & 1 deletion lib/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -2013,7 +2013,7 @@ Schema.prototype.virtual = function(name, options) {
throw new Error('Reference virtuals require `foreignField` option');
}

this.pre('init', function(obj) {
this.pre('init', function virtualPreInit(obj) {
if (mpath.has(name, obj)) {
const _v = mpath.get(name, obj);
if (!this.$$populatedVirtuals) {
Expand Down

0 comments on commit 55112dc

Please sign in to comment.