Skip to content
This repository was archived by the owner on Sep 3, 2022. It is now read-only.

Commit 7d8faaf

Browse files
author
Bryan Mikaelian
committed
Just use ES6 spread syntax merging for everything
1 parent 9c0f101 commit 7d8faaf

File tree

6 files changed

+22
-17
lines changed

6 files changed

+22
-17
lines changed

lib/analytics.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ var querystring = require('component-querystring');
4949
var store = require('./store');
5050
var user = require('./user');
5151
var type = require('component-type');
52-
var assign = require('lodash.assign')
5352

5453
/**
5554
* Initialize a new `Analytics` instance.
@@ -614,13 +613,11 @@ Analytics.prototype.page = function(
614613

615614
// Ensure properties has baseline spec properties.
616615
// TODO: Eventually move these entirely to `options.context.page`
617-
<<<<<<< HEAD
618-
const defs = pageDefaults();
619-
defaults(properties, defs);
620-
=======
621-
var defs = pageDefaults();
622-
assign(properties, defs)
623-
>>>>>>> f1bfcd9... Replace @ndhoulse/defaults with lodash.assign and ES6 spread syntax merging
616+
const defs = pageDefaults()
617+
properties = {
618+
...properties,
619+
...defs
620+
}
624621

625622
// Mirror user overrides to `options.context.page` (but exclude custom properties)
626623
// (Any page defaults get applied in `this.normalize` for consistency.)

lib/cookie.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ var bindAll = require('bind-all');
1111
var cookie = require('@segment/cookie');
1212
var debug = require('debug')('analytics.js:cookie');
1313
var topDomain = require('@segment/top-domain');
14-
var assign = require('lodash.assign')
1514

1615
const MAX_AGE_ONE_YEAR = 31536000000
1716

@@ -44,7 +43,10 @@ Cookie.prototype.options = function(options?: CookieOptions) {
4443
sameSite: 'Lax'
4544
}
4645

47-
this._options = assign(defaults, options);
46+
this._options = {
47+
...defaults,
48+
...options
49+
};
4850

4951
// http://curl.haxx.se/rfc/cookie_spec.html
5052
// https://publicsuffix.org/list/effective_tld_names.dat

lib/normalize.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ var debug = require('debug')('analytics.js:normalize');
99
var type = require('component-type');
1010
var uuid = require('uuid/v4');
1111
var md5 = require('spark-md5').hash;
12-
var assign = require('lodash.assign')
1312

1413

1514
/**
@@ -89,7 +88,11 @@ function normalize(msg: Message, list: Array<any>): NormalizedMessage {
8988
delete msg.options;
9089
ret.integrations = integrations;
9190
ret.context = context;
92-
ret = assign(msg, ret);
91+
ret = {
92+
...msg,
93+
...ret
94+
}
95+
9396
debug('->', ret);
9497
return ret;
9598

lib/store.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { StoreOptions } from './types';
88

99
var bindAll = require('bind-all');
1010
var store = require('@segment/store');
11-
var assign = require('lodash.assign')
1211

1312
/**
1413
* Initialize a new `Store` with `options`.
@@ -28,7 +27,10 @@ Store.prototype.options = function(options?: StoreOptions) {
2827
if (arguments.length === 0) return this._options;
2928

3029
options = options || {};
31-
options = assign({ enabled: true }, options);
30+
options = {
31+
enabled: true,
32+
...options
33+
};
3234

3335
this.enabled = options.enabled && store.enabled;
3436
this._options = options;

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
"lodash.clonedeep": "^4.5.0",
5555
"lodash.includes": "^4.3.0",
5656
"lodash.pick": "^4.4.0",
57-
"lodash.assign": "^4.2.0",
5857
"new-date": "^1.0.0",
5958
"next-tick": "^0.2.2",
6059
"package-json-versionify": "^1.0.4",

test/analytics.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ var pageDefaults = require('../build/pageDefaults');
1111
var sinon = require('sinon');
1212
var tick = require('next-tick');
1313
var trigger = require('compat-trigger-event');
14-
var assign = require('lodash.assign');
1514

1615
var Identify = Facade.Identify;
1716
var cookie = Analytics.cookie;
@@ -1615,7 +1614,10 @@ describe('Analytics', function() {
16151614
var track = analytics._invoke.args[0][1];
16161615
assert.deepEqual(
16171616
track.context().page,
1618-
assign(contextPage, { title: 'lol' })
1617+
{
1618+
...contextPage,
1619+
title: 'lol'
1620+
}
16191621
);
16201622
});
16211623

0 commit comments

Comments
 (0)