Skip to content

Commit

Permalink
perf: reduce package bundle size
Browse files Browse the repository at this point in the history
  • Loading branch information
luin committed Oct 8, 2018
1 parent 1493c81 commit 6dd3730
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 17 deletions.
2 changes: 1 addition & 1 deletion lib/commander.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ commands.push('sentinel');
* @public
*/
Commander.prototype.getBuiltinCommands = function () {
return _.clone(commands);
return commands.slice(0);
};

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/redis.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ Redis.prototype.end = function () {
* @public
*/
Redis.prototype.duplicate = function (override) {
return new Redis(Object.assign(_.cloneDeep(this.options), override || {}));
return new Redis(Object.assign({}, this.options, override || {}));
};

/**
Expand Down
2 changes: 0 additions & 2 deletions lib/utils/lodash.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ exports.pick = require('lodash.pick');
exports.defaults = require('lodash.defaults');
exports.noop = function () {};
exports.difference = require('lodash.difference');
exports.clone = require('lodash.clone');
exports.sample = require('lodash.sample');
exports.flatten = require('lodash.flatten');
exports.bind = require('lodash.bind');
exports.isEmpty = require('lodash.isempty');
exports.values = require('lodash.values');
exports.shuffle = require('lodash.shuffle');
exports.partial = require('lodash.partial');
exports.cloneDeep = require('lodash.clonedeep');
10 changes: 0 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"test:cov": "NODE_ENV=test node ./node_modules/istanbul/lib/cli.js cover --preserve-comments ./node_modules/mocha/bin/_mocha -- -r ts-node/register -R spec --exit",
"build": "rm -rf built && tsc",
"generate-docs": "jsdoc2md lib/redis.js lib/cluster/index.js lib/commander.js > API.md",
"prepublish": "npm run build && npm test",
"prepublishOnly": "npm run build && npm test",
"bench": "matcha benchmarks/*.js"
},
"repository": {
Expand All @@ -33,8 +33,6 @@
"denque": "^1.1.0",
"flexbuffer": "0.0.6",
"lodash.bind": "^4.2.1",
"lodash.clone": "^4.5.0",
"lodash.clonedeep": "^4.5.0",
"lodash.defaults": "^4.2.0",
"lodash.difference": "^4.5.0",
"lodash.flatten": "^4.4.0",
Expand Down
10 changes: 10 additions & 0 deletions test/functional/duplicate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict';

describe('duplicate', () => {
it('clone the options', () => {
var redis = new Redis()
var duplicatedRedis = redis.duplicate()
redis.options.port = 1234
expect(duplicatedRedis.options.port).to.eql(6379)
});
});
10 changes: 10 additions & 0 deletions test/unit/commander.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
var Commander = require('../../lib/commander');

describe('Commander', function () {
describe('#getBuiltinCommands()', () => {
it('returns a new copy of commands', () => {
const c = new Commander()
const commands = c.getBuiltinCommands()
commands.unshift('abc')
const commandsNew = c.getBuiltinCommands()
expect(commands.slice(1)).to.eql(commandsNew)
})
})

it('should pass the correct arguments', function () {
stub(Commander.prototype, 'sendCommand', function (command) {
return command;
Expand Down

0 comments on commit 6dd3730

Please sign in to comment.