MCPcopy
hub / github.com/nytimes/react-tracking / trackEventMethodDecorator

Function trackEventMethodDecorator

src/trackEventMethodDecorator.js:3–37  ·  view source on GitHub ↗
(trackingData = {})

Source from the content-addressed store, hash-verified

1import makeClassMemberDecorator from './makeClassMemberDecorator';
2
3export default function trackEventMethodDecorator(trackingData = {}) {
4 return makeClassMemberDecorator(
5 decoratedFn =>
6 function decorateClassMember(...args) {
7 const trackEvent = (...promiseArguments) => {
8 if (
9 this.props &&
10 this.props.tracking &&
11 typeof this.props.tracking.trackEvent === 'function'
12 ) {
13 const thisTrackingData =
14 typeof trackingData === 'function'
15 ? trackingData(this.props, this.state, args, promiseArguments)
16 : trackingData;
17 if (thisTrackingData) {
18 this.props.tracking.trackEvent(thisTrackingData);
19 }
20 }
21 };
22
23 const fn = Reflect.apply(decoratedFn, this, args);
24 if (Promise && Promise.resolve(fn) === fn) {
25 return fn
26 .then(trackEvent.bind(this))
27 .then(() => fn)
28 .catch(error => {
29 trackEvent({}, error);
30 throw error;
31 });
32 }
33 trackEvent();
34 return fn;
35 }
36 );
37}

Callers 3

hocFunction · 0.85
TestClassClass · 0.85

Calls 2

makeClassMemberDecoratorFunction · 0.85
trackEventFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…