Skip to content

Commit

Permalink
perf: replace lodash.merge with native Object.assign
Browse files Browse the repository at this point in the history
  • Loading branch information
bravo-kernel committed Nov 1, 2019
1 parent 991cea6 commit fd8da33
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 10 deletions.
7 changes: 4 additions & 3 deletions lib/schema-manager.js
@@ -1,4 +1,3 @@
const _merge = require('lodash.merge');
const plural = require('pluralize');
const { capitalize, omit, pick } = require('./utils/lodash-natives');

Expand Down Expand Up @@ -53,7 +52,8 @@ class SchemaManager {
disableComments: true,
};

this._verifyOptions(_merge({}, defaultOptions, options));
// eslint-disable-next-line prefer-object-spread
this._verifyOptions(Object.assign({}, defaultOptions, options));
}

/**
Expand Down Expand Up @@ -85,7 +85,8 @@ class SchemaManager {
if (model === undefined) throw new Error('Missing method argument');
if (strategy === undefined) throw new Error('Mising method argument');

this._verifyModelOptions(_merge({}, defaultOptions, options));
// eslint-disable-next-line prefer-object-spread
this._verifyModelOptions(Object.assign({}, defaultOptions, options));
this._verifyModel(model);
this._verifyStrategy(strategy);

Expand Down
4 changes: 1 addition & 3 deletions lib/type-mapper.js
@@ -1,5 +1,3 @@
const _merge = require('lodash.merge');

// Common types. These should never be exposed directly but, rather, get cloned
// before being returned. This avoids cross-contamination if a user modifies
// the their schema.
Expand Down Expand Up @@ -345,7 +343,7 @@ class TypeMapper {
// Sequelize options applying to all types starting below
// ----------------------------------------------------------------------
if (properties.allowNull === true) {
_merge(result, this.constructor._getNullableType(result.type, strategy));
Object.assign(result, this.constructor._getNullableType(result.type, strategy));
}

if (properties.defaultValue !== undefined) {
Expand Down
5 changes: 2 additions & 3 deletions lib/utils/lodash-natives.js
@@ -1,11 +1,10 @@
/**
* Native alternatives for lodash.
*
* Please note:
* - not using alternatives that do not work cross-browser (see link)
* - disabling eslint rules so examples stay identical to github
* @comment disabling eslint rules so examples stay identical to github
*
* @see {@link https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore}
* @see {@link https://xebia.com/blog/you-might-not-need-lodash-in-your-es2015-project/}
*/

/* eslint-disable func-names */
Expand Down
1 change: 0 additions & 1 deletion package.json
Expand Up @@ -46,7 +46,6 @@
"oasv3"
],
"dependencies": {
"lodash.merge": "^4.6.2",
"pluralize": "^8.0.0"
},
"devDependencies": {
Expand Down

0 comments on commit fd8da33

Please sign in to comment.