-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ivan Kravchenko
committed
Dec 17, 2016
1 parent
518dd9d
commit 25f4307
Showing
8 changed files
with
269 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"plugins": ["transform-runtime", "transform-decorators-legacy"], | ||
"presets": ["es2015", "stage-0", "react"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
src | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
'use strict'; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = dispatchTrackingEvent; | ||
|
||
var _customEvent = require('custom-event'); | ||
|
||
var _customEvent2 = _interopRequireDefault(_customEvent); | ||
|
||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
|
||
function dispatchTrackingEvent(data) { | ||
document.dispatchEvent(new _customEvent2.default('FirehoseTrackingEvent', { | ||
detail: data | ||
})); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
'use strict'; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
|
||
var _withTrackingComponentDecorator = require('./withTrackingComponentDecorator'); | ||
|
||
Object.defineProperty(exports, 'withTracking', { | ||
enumerable: true, | ||
get: function get() { | ||
return _interopRequireDefault(_withTrackingComponentDecorator).default; | ||
} | ||
}); | ||
|
||
var _trackEventMethodDecorator = require('./trackEventMethodDecorator'); | ||
|
||
Object.defineProperty(exports, 'trackEvent', { | ||
enumerable: true, | ||
get: function get() { | ||
return _interopRequireDefault(_trackEventMethodDecorator).default; | ||
} | ||
}); | ||
|
||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
'use strict'; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
|
||
var _defineProperty = require('babel-runtime/core-js/reflect/define-property'); | ||
|
||
var _defineProperty2 = _interopRequireDefault(_defineProperty); | ||
|
||
var _apply = require('babel-runtime/core-js/reflect/apply'); | ||
|
||
var _apply2 = _interopRequireDefault(_apply); | ||
|
||
exports.default = makeClassMemberDecorator; | ||
|
||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
|
||
/** | ||
* Helper to decorate class member | ||
* Supports class plain methods, field syntax and lazy methods | ||
* @param {Function} decorate Actual decorator function. | ||
* Example: | ||
* decoratedFn => function () { | ||
* // do stuff... | ||
* return Reflect.apply(decoratedFn, this, arguments); | ||
* } | ||
* @returns {Function} Class member decorator ((target, name, descriptor) => newDescriptor) | ||
*/ | ||
function makeClassMemberDecorator(decorate) { | ||
return function (target, name, descriptor) { | ||
var configurable = descriptor.configurable, | ||
enumerable = descriptor.enumerable, | ||
value = descriptor.value, | ||
_get = descriptor.get, | ||
initializer = descriptor.initializer; | ||
|
||
|
||
if (value) { | ||
return { | ||
configurable: configurable, | ||
enumerable: enumerable, | ||
value: decorate(value) | ||
}; | ||
} | ||
|
||
// support lazy initializer | ||
if (_get || initializer) { | ||
return { | ||
configurable: configurable, | ||
enumerable: enumerable, | ||
get: function get() { | ||
// This happens if someone accesses the | ||
// property directly on the prototype | ||
if (this === target) { | ||
return null; | ||
} | ||
|
||
var resolvedValue = initializer ? (0, _apply2.default)(initializer, this, []) : (0, _apply2.default)(_get, this, []); | ||
var decoratedValue = decorate(resolvedValue).bind(this); | ||
(0, _defineProperty2.default)(this, name, { | ||
configurable: configurable, | ||
enumerable: enumerable, | ||
value: decoratedValue | ||
}); | ||
return decoratedValue; | ||
} | ||
}; | ||
} | ||
|
||
throw new Error('called makeClassMemberDecorator on unsupported descriptor'); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
'use strict'; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
|
||
var _apply = require('babel-runtime/core-js/reflect/apply'); | ||
|
||
var _apply2 = _interopRequireDefault(_apply); | ||
|
||
exports.default = trackEventMethodDecorator; | ||
|
||
var _makeClassMemberDecorator = require('./makeClassMemberDecorator'); | ||
|
||
var _makeClassMemberDecorator2 = _interopRequireDefault(_makeClassMemberDecorator); | ||
|
||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
|
||
function trackEventMethodDecorator() { | ||
var trackingData = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
|
||
return (0, _makeClassMemberDecorator2.default)(function (decoratedFn) { | ||
return function () { | ||
if (this.props && typeof this.props.trackEvent === 'function') { | ||
var thisTrackingData = typeof trackingData === 'function' ? trackingData(this.props, arguments) : trackingData; | ||
this.props.trackEvent(thisTrackingData); | ||
} | ||
|
||
return (0, _apply2.default)(decoratedFn, this, arguments); | ||
}; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
'use strict'; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
|
||
var _extends2 = require('babel-runtime/helpers/extends'); | ||
|
||
var _extends3 = _interopRequireDefault(_extends2); | ||
|
||
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of'); | ||
|
||
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf); | ||
|
||
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); | ||
|
||
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); | ||
|
||
var _createClass2 = require('babel-runtime/helpers/createClass'); | ||
|
||
var _createClass3 = _interopRequireDefault(_createClass2); | ||
|
||
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn'); | ||
|
||
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2); | ||
|
||
var _inherits2 = require('babel-runtime/helpers/inherits'); | ||
|
||
var _inherits3 = _interopRequireDefault(_inherits2); | ||
|
||
exports.default = withTrackingComponentDecorator; | ||
|
||
var _react = require('react'); | ||
|
||
var _react2 = _interopRequireDefault(_react); | ||
|
||
var _dispatchTrackingEvent = require('./dispatchTrackingEvent'); | ||
|
||
var _dispatchTrackingEvent2 = _interopRequireDefault(_dispatchTrackingEvent); | ||
|
||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
|
||
function withTrackingComponentDecorator() { | ||
var trackingContext = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
|
||
return function (DecoratedComponent) { | ||
var _class, _temp; | ||
|
||
var decoratedComponentName = DecoratedComponent.displayName || DecoratedComponent.name || 'Component'; | ||
|
||
return _temp = _class = function (_Component) { | ||
(0, _inherits3.default)(WithTracking, _Component); | ||
|
||
function WithTracking(props) { | ||
(0, _classCallCheck3.default)(this, WithTracking); | ||
|
||
var _this = (0, _possibleConstructorReturn3.default)(this, (WithTracking.__proto__ || (0, _getPrototypeOf2.default)(WithTracking)).call(this, props)); | ||
|
||
_this.trackEvent = _this.trackEvent.bind(_this); | ||
return _this; | ||
} | ||
|
||
(0, _createClass3.default)(WithTracking, [{ | ||
key: 'getChildContext', | ||
value: function getChildContext() { | ||
var thisTrackingContext = typeof trackingContext === 'function' ? trackingContext(this.props) : trackingContext; | ||
return { | ||
tracking: (0, _extends3.default)({}, this.context.tracking, thisTrackingContext) | ||
}; | ||
} | ||
}, { | ||
key: 'trackEvent', | ||
value: function trackEvent(data) { | ||
(0, _dispatchTrackingEvent2.default)((0, _extends3.default)({}, this.getChildContext().tracking, data)); | ||
} | ||
}, { | ||
key: 'componentDidMount', | ||
value: function componentDidMount() { | ||
if (trackingContext.page) { | ||
this.trackEvent({ | ||
action: 'pageview' | ||
}); | ||
} | ||
} | ||
}, { | ||
key: 'render', | ||
value: function render() { | ||
return _react2.default.createElement(DecoratedComponent, (0, _extends3.default)({}, this.props, { | ||
trackEvent: this.trackEvent | ||
})); | ||
} | ||
}]); | ||
return WithTracking; | ||
}(_react.Component), _class.displayName = 'WithTracking(' + decoratedComponentName + ')', _class.contextTypes = { | ||
tracking: _react.PropTypes.object | ||
}, _class.childContextTypes = { | ||
tracking: _react.PropTypes.object | ||
}, _temp; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters