Skip to content

Commit

Permalink
fix: replace bad 1.0.1 build
Browse files Browse the repository at this point in the history
  • Loading branch information
troch committed Nov 28, 2015
1 parent b941d31 commit 38f767f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
15 changes: 11 additions & 4 deletions dist/commonjs/timer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _invariant = require('invariant');

var _invariant2 = _interopRequireDefault(_invariant);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
Expand All @@ -21,6 +25,8 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

function timer(delay) {
(0, _invariant2.default)(typeof delay === 'number' && delay > 0, '[react-timer-hoc] `delay` should be a number greater than 0.');

return function TimerHoc(TimedComponent) {
var Timer = (function (_React$Component) {
_inherits(Timer, _React$Component);
Expand Down Expand Up @@ -54,17 +60,19 @@ function timer(delay) {
var duration = delay - (this.startTime - Date.now()) % delay;
this.timer = setTimeout(function () {
_this2.setState({ tick: _this2.state.tick + 1 });
_this2.setTimeout();
if (!_this2.stopped) _this2.setTimeout();
}, delay);
})
}, {
key: 'stop',
value: function stop() {
this.stopped = true;
clearTimeout(this.timer);
}
}, {
key: 'componentDidMount',
value: function componentDidMount() {
this.stopped = false;
this.startTime = Date.now();
this.setTimeout();
}
Expand All @@ -76,9 +84,8 @@ function timer(delay) {
}, {
key: 'render',
value: function render() {
var _props = this.props;
var props = _props.props;
var stop = _props.stop;
var props = this.props;
var stop = this.stop;
var tick = this.state.tick;

return _react2.default.createElement(TimedComponent, _extends({}, props, { tick: tick, delay: delay, stop: stop }));
Expand Down
20 changes: 12 additions & 8 deletions dist/umd/timer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,25 @@ function _typeof(obj) { return obj && typeof Symbol !== "undefined" && obj.const

(function (global, factory) {
if (typeof define === "function" && define.amd) {
define(['exports', 'react'], factory);
define(['exports', 'react', 'invariant'], factory);
} else if (typeof exports !== "undefined") {
factory(exports, require('react'));
factory(exports, require('react'), require('invariant'));
} else {
var mod = {
exports: {}
};
factory(mod.exports, global.react);
factory(mod.exports, global.react, global.invariant);
global.timer = mod.exports;
}
})(this, function (exports, _react) {
})(this, function (exports, _react, _invariant) {
Object.defineProperty(exports, "__esModule", {
value: true
});

var _react2 = _interopRequireDefault(_react);

var _invariant2 = _interopRequireDefault(_invariant);

function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : {
default: obj
Expand Down Expand Up @@ -90,6 +92,7 @@ function _typeof(obj) { return obj && typeof Symbol !== "undefined" && obj.const
}

function timer(delay) {
(0, _invariant2.default)(typeof delay === 'number' && delay > 0, '[react-timer-hoc] `delay` should be a number greater than 0.');
return function TimerHoc(TimedComponent) {
var Timer = (function (_React$Component) {
_inherits(Timer, _React$Component);
Expand Down Expand Up @@ -128,17 +131,19 @@ function _typeof(obj) { return obj && typeof Symbol !== "undefined" && obj.const
tick: _this2.state.tick + 1
});

_this2.setTimeout();
if (!_this2.stopped) _this2.setTimeout();
}, delay);
})
}, {
key: 'stop',
value: function stop() {
this.stopped = true;
clearTimeout(this.timer);
}
}, {
key: 'componentDidMount',
value: function componentDidMount() {
this.stopped = false;
this.startTime = Date.now();
this.setTimeout();
}
Expand All @@ -150,9 +155,8 @@ function _typeof(obj) { return obj && typeof Symbol !== "undefined" && obj.const
}, {
key: 'render',
value: function render() {
var _props = this.props;
var props = _props.props;
var stop = _props.stop;
var props = this.props;
var stop = this.stop;
var tick = this.state.tick;
return _react2.default.createElement(TimedComponent, _extends({}, props, {
tick: tick,
Expand Down
7 changes: 5 additions & 2 deletions modules/timer.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React from 'react';
import invariant from 'invariant';

function timer(delay) {
invariant(
typeof delay !== 'number' || delay === 0 || delay < 0,
typeof delay === 'number' && delay > 0,
'[react-timer-hoc] `delay` should be a number greater than 0.'
);

Expand All @@ -19,15 +20,17 @@ function timer(delay) {
const duration = delay - (this.startTime - Date.now()) % delay;
this.timer = setTimeout(() => {
this.setState({ tick: this.state.tick + 1 });
this.setTimeout();
if (!this.stopped) this.setTimeout();
}, delay);
}

stop() {
this.stopped = true;
clearTimeout(this.timer);
}

componentDidMount() {
this.stopped = false;
this.startTime = Date.now();
this.setTimeout();
}
Expand Down

0 comments on commit 38f767f

Please sign in to comment.