Skip to content

Commit

Permalink
refactor: use es6 syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Jun 21, 2020
1 parent 99edef3 commit 849ea60
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
8 changes: 3 additions & 5 deletions lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,7 @@ class Model extends EventEmitter {
* @param {Boolean} [options.lean=false] Returns a plain JavaScript object.
* @return {Query|Array}
*/
find(query, options_) {
const options = options_ || {};
find(query, options = {}) {
const filter = this.schema._execQuery(query);
const keys = Object.keys(this.data);
const len = keys.length;
Expand Down Expand Up @@ -486,8 +485,7 @@ class Model extends EventEmitter {
* @param {Boolean} [options.lean=false] Returns a plain JavaScript object.
* @return {Document|Object}
*/
findOne(query, options_) {
const options = options_ || {};
findOne(query, options = {}) {
options.limit = 1;

const result = this.find(query, options);
Expand Down Expand Up @@ -518,7 +516,7 @@ class Model extends EventEmitter {
*/
eq(i_, options) {
let index = i_ < 0 ? this.length + i_ : i_;
const data = this.data;
const { data } = this;
const keys = Object.keys(data);

for (let i = 0, len = keys.length; i < len; i++) {
Expand Down
8 changes: 4 additions & 4 deletions lib/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class UpdateParser {
*/
parseUpdate(updates, prefix = '', stack = []) {
const { paths } = this;
const { updateStackOperator } = UpdateParser;
const { updateStackOperator, updateStackNormal } = UpdateParser;
const keys = Object.keys(updates);
let path, prefixNoDot;

Expand All @@ -129,7 +129,7 @@ class UpdateParser {
const name = prefix + key;

// Update operators
if (key[0] === '$') {
if (key.startsWith('$')) {
const ukey = `u${key}`;

// First-class update operators
Expand All @@ -147,7 +147,7 @@ class UpdateParser {
} else if (isPlainObject(update)) {
this.parseUpdate(update, `${name}.`, stack);
} else {
stack.push(UpdateParser.updateStackNormal(name, update));
stack.push(updateStackNormal(name, update));
}
}

Expand Down Expand Up @@ -298,7 +298,7 @@ class QueryParser {
const key = keys[i];
const query = queries[key];

if (key[0] === '$') {
if (key.startsWith('$')) {
stack.push(this.queryStackOperator(`q${key}`, prefix, query));
continue;
}
Expand Down

0 comments on commit 849ea60

Please sign in to comment.