Skip to content

Commit 6b89fa5

Browse files
authored
Merge pull request #453 from Meteor-Community-Packages/feature/forofloops
Few forEach to for of loop
2 parents 419ce5c + d4b4949 commit 6b89fa5

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

package/collection2/lib.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export function flattenSelector(selector) {
1010

1111
const obj = {};
1212

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

3030
return obj;
3131
}

package/collection2/main.js

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ Mongo.Collection.prototype.attachSchema = function c2AttachSchema(ss, options) {
114114
Collection2.emit('schema.attached', this, ss, options);
115115
};
116116

117-
[Mongo.Collection, LocalCollection].forEach((obj) => {
117+
for (const obj of [Mongo.Collection, LocalCollection]) {
118118
/**
119119
* simpleSchema
120120
* @description function detect the correct schema by given params. If it
@@ -129,15 +129,15 @@ Mongo.Collection.prototype.attachSchema = function c2AttachSchema(ss, options) {
129129
obj.prototype.simpleSchema = function (doc, options, query) {
130130
if (!this._c2) return null;
131131
if (this._c2._simpleSchema) return this._c2._simpleSchema;
132-
132+
133133
const schemas = this._c2._simpleSchemas;
134134
if (schemas && schemas.length > 0) {
135135
let schema, selector, target;
136136
// Position 0 reserved for base schema
137137
for (let i = 1; i < schemas.length; i++) {
138138
schema = schemas[i];
139139
selector = Object.keys(schema.selector)[0];
140-
140+
141141
// We will set this to undefined because in theory, you might want to select
142142
// on a null value.
143143
target = undefined;
@@ -153,7 +153,7 @@ Mongo.Collection.prototype.attachSchema = function c2AttachSchema(ss, options) {
153153
// on upsert/update operations
154154
target = query[selector];
155155
}
156-
156+
157157
// we need to compare given selector with doc property or option to
158158
// find the right schema
159159
if (target !== undefined && target === schema.selector[selector]) {
@@ -166,12 +166,12 @@ Mongo.Collection.prototype.attachSchema = function c2AttachSchema(ss, options) {
166166
throw new Error('No default schema');
167167
}
168168
}
169-
169+
170170
return null;
171171
};
172-
});
172+
}
173173

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

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

423423
const cleanOptionsForThisOperation = {};
424-
['autoConvert', 'filter', 'removeEmptyStrings', 'removeNullsFromArrays', 'trimStrings'].forEach(
425-
(prop) => {
426-
if (typeof options[prop] === 'boolean') {
427-
cleanOptionsForThisOperation[prop] = options[prop];
428-
}
424+
for (const prop of ['autoConvert', 'filter', 'removeEmptyStrings', 'removeNullsFromArrays', 'trimStrings']) {
425+
if (typeof options[prop] === 'boolean') {
426+
cleanOptionsForThisOperation[prop] = options[prop];
429427
}
430-
);
431-
428+
}
429+
432430
// Preliminary cleaning on both client and server. On the server and for local
433431
// collections, automatic values will also be set at this point.
434432
schema.clean(doc, {

0 commit comments

Comments
 (0)