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

Replace @ndhoule/defaults with ES6 spread syntax merging #185

Merged
merged 7 commits into from
Sep 17, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Just use ES6 spread syntax merging for everything
  • Loading branch information
Bryan Mikaelian committed Sep 17, 2020
commit de834bf064e8c5de397bd2d8ebe0f221b25bc0e6
2 changes: 1 addition & 1 deletion HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 4.1.5 / 2020-09-17

- Replace @ndhoule/defaults with lodash.assign and ES6 spread syntax
- Replace @ndhoule/defaults with merging via ES6 spread syntax

# 4.1.4 / 2020-09-16

Expand Down
13 changes: 5 additions & 8 deletions lib/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ var querystring = require('component-querystring');
var store = require('./store');
var user = require('./user');
var type = require('component-type');
var assign = require('lodash.assign')

/**
* Initialize a new `Analytics` instance.
Expand Down Expand Up @@ -614,13 +613,11 @@ Analytics.prototype.page = function(

// Ensure properties has baseline spec properties.
// TODO: Eventually move these entirely to `options.context.page`
<<<<<<< HEAD
const defs = pageDefaults();
defaults(properties, defs);
=======
var defs = pageDefaults();
assign(properties, defs)
>>>>>>> f1bfcd9... Replace @ndhoulse/defaults with lodash.assign and ES6 spread syntax merging
const defs = pageDefaults()
properties = {
...properties,
...defs
}

// Mirror user overrides to `options.context.page` (but exclude custom properties)
// (Any page defaults get applied in `this.normalize` for consistency.)
Expand Down
6 changes: 4 additions & 2 deletions lib/cookie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ var bindAll = require('bind-all');
var cookie = require('@segment/cookie');
var debug = require('debug')('analytics.js:cookie');
var topDomain = require('@segment/top-domain');
var assign = require('lodash.assign')

const MAX_AGE_ONE_YEAR = 31536000000

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

this._options = assign(defaults, options);
this._options = {
...defaults,
...options
};

// http://curl.haxx.se/rfc/cookie_spec.html
// https://publicsuffix.org/list/effective_tld_names.dat
Expand Down
7 changes: 5 additions & 2 deletions lib/normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ var debug = require('debug')('analytics.js:normalize');
var type = require('component-type');
var uuid = require('uuid/v4');
var md5 = require('spark-md5').hash;
var assign = require('lodash.assign')


/**
Expand Down Expand Up @@ -89,7 +88,11 @@ function normalize(msg: Message, list: Array<any>): NormalizedMessage {
delete msg.options;
ret.integrations = integrations;
ret.context = context;
ret = assign(msg, ret);
ret = {
...msg,
...ret
}

debug('->', ret);
return ret;

Expand Down
6 changes: 4 additions & 2 deletions lib/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { StoreOptions } from './types';

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

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

options = options || {};
options = assign({ enabled: true }, options);
options = {
enabled: true,
...options
};

this.enabled = options.enabled && store.enabled;
this._options = options;
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
"lodash.clonedeep": "^4.5.0",
"lodash.includes": "^4.3.0",
"lodash.pick": "^4.4.0",
"lodash.assign": "^4.2.0",
"new-date": "^1.0.0",
"next-tick": "^0.2.2",
"package-json-versionify": "^1.0.4",
Expand Down
6 changes: 4 additions & 2 deletions test/analytics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ var pageDefaults = require('../build/pageDefaults');
var sinon = require('sinon');
var tick = require('next-tick');
var trigger = require('compat-trigger-event');
var assign = require('lodash.assign');

var Identify = Facade.Identify;
var cookie = Analytics.cookie;
Expand Down Expand Up @@ -1615,7 +1614,10 @@ describe('Analytics', function() {
var track = analytics._invoke.args[0][1];
assert.deepEqual(
track.context().page,
assign(contextPage, { title: 'lol' })
{
...contextPage,
title: 'lol'
}
);
});

Expand Down