@vrbo/react-event-tracking
Advanced tools
Comparing version 1.2.0 to 1.3.0
@@ -8,1 +8,6 @@ | ||
and this project adheres to [Semantic Versioning](http://semver.org/). | ||
## [1.3.0] - 2021-04-07 | ||
### Changed | ||
- `mergeContextData` in `TrackingProvider` uses deep merge to merge payload and options context values. | ||
- `trigger` function in `TrackingProvider` uses deep merge to merge context data with trigger data. |
@@ -1,4 +0,4 @@ | ||
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); } | ||
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; } | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
@@ -23,2 +23,3 @@ /* | ||
import TrackingContext from '../../context/TrackingContext'; | ||
import deepMerge from '../../utils/DeepMerge'; | ||
/** | ||
@@ -58,4 +59,4 @@ * A React context provider that allows nesting to generate new context that | ||
payload = _extends({}, data.payload, eventPayload, payload); | ||
options = _extends({}, data.options, eventOptions, options); | ||
payload = deepMerge(data.payload, eventPayload, payload); | ||
options = deepMerge(data.options, eventOptions, options); | ||
return data.trigger(name, payload, options); | ||
@@ -137,19 +138,6 @@ }; | ||
// Not an overwrite so merge the properties and context objects | ||
newData.eventPayload = _extends({}, data.eventPayload, eventPayload); | ||
newData.eventOptions = _extends({}, data.eventOptions, eventOptions); | ||
newData.payload = _extends({}, data.payload, payload); | ||
newData.options = _extends({}, data.options, options); // if eventFields, eventPayload or eventOptions was specified need to do a shallow | ||
// copy and another shallow copy one level deep for each key. | ||
if (eventPayload) { | ||
Object.keys(newData.eventPayload).forEach(function (key) { | ||
newData.eventPayload[key] = _extends({}, data.eventPayload[key], eventPayload[key]); | ||
}); | ||
} | ||
if (eventOptions) { | ||
Object.keys(newData.eventOptions).forEach(function (key) { | ||
newData.eventOptions[key] = _extends({}, data.eventOptions[key], eventOptions[key]); | ||
}); | ||
} | ||
newData.eventPayload = deepMerge(data.eventPayload, eventPayload); | ||
newData.eventOptions = deepMerge(data.eventOptions, eventOptions); | ||
newData.payload = deepMerge(data.payload, payload); | ||
newData.options = deepMerge(data.options, options); | ||
} | ||
@@ -156,0 +144,0 @@ |
@@ -1,3 +0,5 @@ | ||
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; } | ||
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); } | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
/* | ||
@@ -4,0 +6,0 @@ * Copyright 2019 Expedia Group, Inc. |
@@ -12,2 +12,4 @@ "use strict"; | ||
var _DeepMerge = _interopRequireDefault(require("../../utils/DeepMerge")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -19,5 +21,5 @@ | ||
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); } | ||
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; } | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
@@ -57,4 +59,4 @@ /** | ||
payload = _extends({}, data.payload, eventPayload, payload); | ||
options = _extends({}, data.options, eventOptions, options); | ||
payload = (0, _DeepMerge.default)(data.payload, eventPayload, payload); | ||
options = (0, _DeepMerge.default)(data.options, eventOptions, options); | ||
return data.trigger(name, payload, options); | ||
@@ -136,19 +138,6 @@ }; | ||
// Not an overwrite so merge the properties and context objects | ||
newData.eventPayload = _extends({}, data.eventPayload, eventPayload); | ||
newData.eventOptions = _extends({}, data.eventOptions, eventOptions); | ||
newData.payload = _extends({}, data.payload, payload); | ||
newData.options = _extends({}, data.options, options); // if eventFields, eventPayload or eventOptions was specified need to do a shallow | ||
// copy and another shallow copy one level deep for each key. | ||
if (eventPayload) { | ||
Object.keys(newData.eventPayload).forEach(function (key) { | ||
newData.eventPayload[key] = _extends({}, data.eventPayload[key], eventPayload[key]); | ||
}); | ||
} | ||
if (eventOptions) { | ||
Object.keys(newData.eventOptions).forEach(function (key) { | ||
newData.eventOptions[key] = _extends({}, data.eventOptions[key], eventOptions[key]); | ||
}); | ||
} | ||
newData.eventPayload = (0, _DeepMerge.default)(data.eventPayload, eventPayload); | ||
newData.eventOptions = (0, _DeepMerge.default)(data.eventOptions, eventOptions); | ||
newData.payload = (0, _DeepMerge.default)(data.payload, payload); | ||
newData.options = (0, _DeepMerge.default)(data.options, options); | ||
} | ||
@@ -155,0 +144,0 @@ |
@@ -18,4 +18,6 @@ "use strict"; | ||
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; } | ||
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); } | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
/** | ||
@@ -22,0 +24,0 @@ * A React component to declaratively trigger an event. The event is |
@@ -1,2 +0,2 @@ | ||
!function(e,t){if("object"===typeof exports&&"object"===typeof module)module.exports=t(require("prop-types"),require("react"));else if("function"===typeof define&&define.amd)define(["prop-types","react"],t);else{var r="object"===typeof exports?t(require("prop-types"),require("react")):t(e["prop-types"],e.react);for(var n in r)("object"===typeof exports?exports:e)[n]=r[n]}}(window,(function(e,t){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"===typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=2)}([function(t,r){t.exports=e},function(e,r){e.exports=t},function(e,t,r){"use strict";r.r(t),r.d(t,"TrackingContext",(function(){return i})),r.d(t,"TrackingProvider",(function(){return f})),r.d(t,"TrackingTrigger",(function(){return l}));var n=r(1),o=r.n(n),a={_data:{eventPayload:{},eventOptions:{},payload:{},options:{},trigger:null},hasProvider:!1,trigger:function(){}},i=o.a.createContext(a),p=r(0),c=r.n(p);function s(){return(s=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}var u=function(e){var t,r;function n(t){var r;return(r=e.call(this,t)||this).trigger=function(e,t,n){void 0===t&&(t={}),void 0===n&&(n={});var o=r.TrackingContext._data,a=e||o.event,i=o.eventPayload?o.eventPayload[a]:{},p=o.eventOptions?o.eventOptions[a]:{};if(!a)throw new TypeError("event is a required parameter");return t=s({},o.payload,i,t),n=s({},o.options,p,n),o.trigger(a,t,n)},r.renderProvider=function(e){var t=(void 0===e?{}:e)._data,n=r.props,a=n.children,p=n.trigger;return r.TrackingContext._data=r.mergeContextData(t),r.TrackingContext._data.trigger=p||t.trigger||function(){},o.a.createElement(i.Provider,{value:r.TrackingContext},a)},r.TrackingContext={_data:{eventPayload:r.props.eventPayload,eventOptions:r.props.eventOptions,payload:r.props.payload,options:r.props.options,trigger:r.props.trigger||function(){}},hasProvider:!0,trigger:r.trigger},r}r=e,(t=n).prototype=Object.create(r.prototype),t.prototype.constructor=t,t.__proto__=r;var a=n.prototype;return a.mergeContextData=function(e){void 0===e&&(e={eventPayload:{},eventFields:{},eventOptions:{}});var t=this.props,r=t.eventFields,n=t.eventOptions,o=t.fields,a=t.options,i=t.overwrite,p=this.props,c=p.eventPayload,u=p.payload,f={};return c=c||r,u=u||o,i?(f.eventPayload=c||e.eventPayload,f.eventOptions=n||e.eventOptions,f.payload=u||e.payload,f.options=a||e.options):(f.eventPayload=s({},e.eventPayload,c),f.eventOptions=s({},e.eventOptions,n),f.payload=s({},e.payload,u),f.options=s({},e.options,a),c&&Object.keys(f.eventPayload).forEach((function(t){f.eventPayload[t]=s({},e.eventPayload[t],c[t])})),n&&Object.keys(f.eventOptions).forEach((function(t){f.eventOptions[t]=s({},e.eventOptions[t],n[t])}))),f},a.render=function(){return o.a.createElement(i.Consumer,null,this.renderProvider)},n}(n.PureComponent);u.propTypes={eventFields:c.a.objectOf(c.a.objectOf(c.a.string)),eventPayload:c.a.objectOf(c.a.objectOf(c.a.any)),eventOptions:c.a.objectOf(c.a.objectOf(c.a.any)),fields:c.a.objectOf(c.a.string),payload:c.a.objectOf(c.a.any),options:c.a.objectOf(c.a.any),overwrite:c.a.bool,trigger:c.a.func},u.defaultProps={overwrite:!1};var f=u;var d=function(e){var t,r;function n(){for(var t,r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];return(t=e.call.apply(e,[this].concat(n))||this).handleContext=function(e){var r=e.trigger,n=t.props.children;return t.trigger=r,n},t}r=e,(t=n).prototype=Object.create(r.prototype),t.prototype.constructor=t,t.__proto__=r;var a=n.prototype;return a.componentDidMount=function(){var e=this.props,t=e.event,r=e.fields,n=e.onTrigger,o=e.options,a=this.props.payload;(a=a||r||{},"function"===typeof this.trigger)&&n(this.trigger(t,a,o))},a.render=function(){return o.a.createElement(i.Consumer,null,this.handleContext)},n}(n.PureComponent);d.propTypes={event:c.a.string.isRequired,fields:c.a.objectOf(c.a.string),payload:c.a.objectOf(c.a.any),onTrigger:c.a.func,options:c.a.objectOf(c.a.string)},d.defaultProps={onTrigger:function(){},options:{}};var l=d}])})); | ||
!function(e,t){if("object"===typeof exports&&"object"===typeof module)module.exports=t(require("prop-types"),require("react"));else if("function"===typeof define&&define.amd)define(["prop-types","react"],t);else{var r="object"===typeof exports?t(require("prop-types"),require("react")):t(e["prop-types"],e.react);for(var n in r)("object"===typeof exports?exports:e)[n]=r[n]}}(window,(function(e,t){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"===typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=2)}([function(t,r){t.exports=e},function(e,r){e.exports=t},function(e,t,r){"use strict";r.r(t),r.d(t,"TrackingContext",(function(){return i})),r.d(t,"TrackingProvider",(function(){return d})),r.d(t,"TrackingTrigger",(function(){return y}));var n=r(1),o=r.n(n),a={_data:{eventPayload:{},eventOptions:{},payload:{},options:{},trigger:null},hasProvider:!1,trigger:function(){}},i=o.a.createContext(a),p=r(0),u=r.n(p);var c=function e(){for(var t=function(e){return e&&"object"===typeof e},r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];return n.reduce((function(r,n){return n?(Object.keys(n).forEach((function(o){var a;Array.isArray(r[o])&&Array.isArray(n[o])?r[o]=(a=r[o]).concat.apply(a,n[o]):t(r[o])&&t(n[o])?r[o]=e(r[o],n[o]):r[o]=n[o]})),r):r}),{})};function s(e,t){return(s=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}var f=function(e){var t,r;function n(t){var r;return(r=e.call(this,t)||this).trigger=function(e,t,n){void 0===t&&(t={}),void 0===n&&(n={});var o=r.TrackingContext._data,a=e||o.event,i=o.eventPayload?o.eventPayload[a]:{},p=o.eventOptions?o.eventOptions[a]:{};if(!a)throw new TypeError("event is a required parameter");return t=c(o.payload,i,t),n=c(o.options,p,n),o.trigger(a,t,n)},r.renderProvider=function(e){var t=(void 0===e?{}:e)._data,n=r.props,a=n.children,p=n.trigger;return r.TrackingContext._data=r.mergeContextData(t),r.TrackingContext._data.trigger=p||t.trigger||function(){},o.a.createElement(i.Provider,{value:r.TrackingContext},a)},r.TrackingContext={_data:{eventPayload:r.props.eventPayload,eventOptions:r.props.eventOptions,payload:r.props.payload,options:r.props.options,trigger:r.props.trigger||function(){}},hasProvider:!0,trigger:r.trigger},r}r=e,(t=n).prototype=Object.create(r.prototype),t.prototype.constructor=t,s(t,r);var a=n.prototype;return a.mergeContextData=function(e){void 0===e&&(e={eventPayload:{},eventFields:{},eventOptions:{}});var t=this.props,r=t.eventFields,n=t.eventOptions,o=t.fields,a=t.options,i=t.overwrite,p=this.props,u=p.eventPayload,s=p.payload,f={};return u=u||r,s=s||o,i?(f.eventPayload=u||e.eventPayload,f.eventOptions=n||e.eventOptions,f.payload=s||e.payload,f.options=a||e.options):(f.eventPayload=c(e.eventPayload,u),f.eventOptions=c(e.eventOptions,n),f.payload=c(e.payload,s),f.options=c(e.options,a)),f},a.render=function(){return o.a.createElement(i.Consumer,null,this.renderProvider)},n}(n.PureComponent);f.propTypes={eventFields:u.a.objectOf(u.a.objectOf(u.a.string)),eventPayload:u.a.objectOf(u.a.objectOf(u.a.any)),eventOptions:u.a.objectOf(u.a.objectOf(u.a.any)),fields:u.a.objectOf(u.a.string),payload:u.a.objectOf(u.a.any),options:u.a.objectOf(u.a.any),overwrite:u.a.bool,trigger:u.a.func},f.defaultProps={overwrite:!1};var d=f;function l(e,t){return(l=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}var v=function(e){var t,r;function n(){for(var t,r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];return(t=e.call.apply(e,[this].concat(n))||this).handleContext=function(e){var r=e.trigger,n=t.props.children;return t.trigger=r,n},t}r=e,(t=n).prototype=Object.create(r.prototype),t.prototype.constructor=t,l(t,r);var a=n.prototype;return a.componentDidMount=function(){var e=this.props,t=e.event,r=e.fields,n=e.onTrigger,o=e.options,a=this.props.payload;(a=a||r||{},"function"===typeof this.trigger)&&n(this.trigger(t,a,o))},a.render=function(){return o.a.createElement(i.Consumer,null,this.handleContext)},n}(n.PureComponent);v.propTypes={event:u.a.string.isRequired,fields:u.a.objectOf(u.a.string),payload:u.a.objectOf(u.a.any),onTrigger:u.a.func,options:u.a.objectOf(u.a.string)},v.defaultProps={onTrigger:function(){},options:{}};var y=v}])})); | ||
//# sourceMappingURL=index.min.js.map |
{ | ||
"name": "@vrbo/react-event-tracking", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "React shared context utilities for analytic event tracking.", | ||
@@ -5,0 +5,0 @@ "license": "Apache-2.0", |
@@ -160,3 +160,3 @@ [![Build Status](https://travis-ci.org/ExpediaGroup/react-event-tracking.svg?branch=master)](https://travis-ci.org/ExpediaGroup/react-event-tracking) | ||
* Do not dynamically construct the property values for `TrackingProvider` unless you want all descendant consumers to force re-render. See the "Note" under the `TrackingProvider` section for more details. | ||
* Objects used in `eventPayload`, `eventOptions` and `payload` are shallow copied when merging data in the `TrackingProvider`, so changes to referenced objects would be reflected in all usages. Use new objects to avoid this. | ||
* Objects used in `eventPayload`, `eventOptions` and `payload` are deep merged when merging data in the `TrackingProvider`. Arrays are concatinated (nested objects within arrays are not merged), objects are merged recursively. Attributes with different types will be overwritten. | ||
@@ -163,0 +163,0 @@ ## Development |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
134747
32
693
1