(trackingData = {})
| 1 | import makeClassMemberDecorator from './makeClassMemberDecorator'; |
| 2 | |
| 3 | export 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 | } |
no test coverage detected
searching dependent graphs…