Skip to content

Commit

Permalink
Merge pull request #453 from Meteor-Community-Packages/feature/forofl…
Browse files Browse the repository at this point in the history
…oops

Few forEach to for of loop
  • Loading branch information
jankapunkt authored Nov 21, 2024
2 parents 419ce5c + d4b4949 commit 6b89fa5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
4 changes: 2 additions & 2 deletions package/collection2/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function flattenSelector(selector) {

const obj = {};

Object.entries(selector).forEach(([key, value]) => {
for (const [key, value] of Object.entries(selector) || []) {
// Ignoring logical selectors (https://docs.mongodb.com/manual/reference/operator/query/#logical)
if (!key.startsWith('$')) {
if (typeof value === 'object' && value !== null) {
Expand All @@ -25,7 +25,7 @@ export function flattenSelector(selector) {
obj[key] = value;
}
}
});
}

return obj;
}
Expand Down
26 changes: 12 additions & 14 deletions package/collection2/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ Mongo.Collection.prototype.attachSchema = function c2AttachSchema(ss, options) {
Collection2.emit('schema.attached', this, ss, options);
};

[Mongo.Collection, LocalCollection].forEach((obj) => {
for (const obj of [Mongo.Collection, LocalCollection]) {
/**
* simpleSchema
* @description function detect the correct schema by given params. If it
Expand All @@ -129,15 +129,15 @@ Mongo.Collection.prototype.attachSchema = function c2AttachSchema(ss, options) {
obj.prototype.simpleSchema = function (doc, options, query) {
if (!this._c2) return null;
if (this._c2._simpleSchema) return this._c2._simpleSchema;

const schemas = this._c2._simpleSchemas;
if (schemas && schemas.length > 0) {
let schema, selector, target;
// Position 0 reserved for base schema
for (let i = 1; i < schemas.length; i++) {
schema = schemas[i];
selector = Object.keys(schema.selector)[0];

// We will set this to undefined because in theory, you might want to select
// on a null value.
target = undefined;
Expand All @@ -153,7 +153,7 @@ Mongo.Collection.prototype.attachSchema = function c2AttachSchema(ss, options) {
// on upsert/update operations
target = query[selector];
}

// we need to compare given selector with doc property or option to
// find the right schema
if (target !== undefined && target === schema.selector[selector]) {
Expand All @@ -166,12 +166,12 @@ Mongo.Collection.prototype.attachSchema = function c2AttachSchema(ss, options) {
throw new Error('No default schema');
}
}

return null;
};
});
}

function getArgumentsAndValidationContext(methodName, args, async) {
function getArgumentsAndValidationContext(methodName, args, async) {
let options = isInsertType(methodName) ? args[1] : args[2];

// Support missing options arg
Expand Down Expand Up @@ -421,14 +421,12 @@ Mongo.Collection.prototype.attachSchema = function c2AttachSchema(ss, options) {
};

const cleanOptionsForThisOperation = {};
['autoConvert', 'filter', 'removeEmptyStrings', 'removeNullsFromArrays', 'trimStrings'].forEach(
(prop) => {
if (typeof options[prop] === 'boolean') {
cleanOptionsForThisOperation[prop] = options[prop];
}
for (const prop of ['autoConvert', 'filter', 'removeEmptyStrings', 'removeNullsFromArrays', 'trimStrings']) {
if (typeof options[prop] === 'boolean') {
cleanOptionsForThisOperation[prop] = options[prop];
}
);
}

// Preliminary cleaning on both client and server. On the server and for local
// collections, automatic values will also be set at this point.
schema.clean(doc, {
Expand Down

0 comments on commit 6b89fa5

Please sign in to comment.