Skip to content

Commit

Permalink
0.8.2 precompile
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Kravchenko committed Dec 17, 2016
1 parent 518dd9d commit 25f4307
Show file tree
Hide file tree
Showing 8 changed files with 269 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .babelrc
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"]
}
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
src
node_modules
18 changes: 18 additions & 0 deletions build/dispatchTrackingEvent.js
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
}));
}
25 changes: 25 additions & 0 deletions build/index.js
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 }; }
73 changes: 73 additions & 0 deletions build/makeClassMemberDecorator.js
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');
};
}
32 changes: 32 additions & 0 deletions build/trackEventMethodDecorator.js
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);
};
});
}
100 changes: 100 additions & 0 deletions build/withTrackingComponentDecorator.js
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;
};
}
18 changes: 15 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "nyt-react-tracking",
"version": "0.8.1",
"version": "0.8.2",
"description": "Experimental \"tracking layer\" implementation for React. The core idea is to provide declarative way to add tracking for React applications.",
"main": "src/index.js",
"main": "build/index.js",
"repository": {
"type": "git",
"url": "git+https://github.com/nytm/nyt-react-tracking.git"
Expand All @@ -20,6 +20,18 @@
"custom-event": "^1.0.1"
},
"peerDependencies": {
"react": "^15.0.0"
"react": "^15.0.0",
"babel-runtime": "^6.20.0"
},
"devDependencies": {
"babel-cli": "^6.18.0",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-plugin-transform-runtime": "^6.15.0",
"babel-preset-es2015": "^6.18.0",
"babel-preset-react": "^6.16.0",
"babel-preset-stage-0": "^6.16.0"
},
"scripts": {
"build": "babel --out-dir build src"
}
}

0 comments on commit 25f4307

Please sign in to comment.