Skip to content

Commit 38f767f

Browse files
committed
fix: replace bad 1.0.1 build
1 parent b941d31 commit 38f767f

File tree

3 files changed

+28
-14
lines changed

3 files changed

+28
-14
lines changed

dist/commonjs/timer.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ var _react = require('react');
1212

1313
var _react2 = _interopRequireDefault(_react);
1414

15+
var _invariant = require('invariant');
16+
17+
var _invariant2 = _interopRequireDefault(_invariant);
18+
1519
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1620

1721
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
@@ -21,6 +25,8 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen
2125
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; }
2226

2327
function timer(delay) {
28+
(0, _invariant2.default)(typeof delay === 'number' && delay > 0, '[react-timer-hoc] `delay` should be a number greater than 0.');
29+
2430
return function TimerHoc(TimedComponent) {
2531
var Timer = (function (_React$Component) {
2632
_inherits(Timer, _React$Component);
@@ -54,17 +60,19 @@ function timer(delay) {
5460
var duration = delay - (this.startTime - Date.now()) % delay;
5561
this.timer = setTimeout(function () {
5662
_this2.setState({ tick: _this2.state.tick + 1 });
57-
_this2.setTimeout();
63+
if (!_this2.stopped) _this2.setTimeout();
5864
}, delay);
5965
})
6066
}, {
6167
key: 'stop',
6268
value: function stop() {
69+
this.stopped = true;
6370
clearTimeout(this.timer);
6471
}
6572
}, {
6673
key: 'componentDidMount',
6774
value: function componentDidMount() {
75+
this.stopped = false;
6876
this.startTime = Date.now();
6977
this.setTimeout();
7078
}
@@ -76,9 +84,8 @@ function timer(delay) {
7684
}, {
7785
key: 'render',
7886
value: function render() {
79-
var _props = this.props;
80-
var props = _props.props;
81-
var stop = _props.stop;
87+
var props = this.props;
88+
var stop = this.stop;
8289
var tick = this.state.tick;
8390

8491
return _react2.default.createElement(TimedComponent, _extends({}, props, { tick: tick, delay: delay, stop: stop }));

dist/umd/timer.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,25 @@ function _typeof(obj) { return obj && typeof Symbol !== "undefined" && obj.const
44

55
(function (global, factory) {
66
if (typeof define === "function" && define.amd) {
7-
define(['exports', 'react'], factory);
7+
define(['exports', 'react', 'invariant'], factory);
88
} else if (typeof exports !== "undefined") {
9-
factory(exports, require('react'));
9+
factory(exports, require('react'), require('invariant'));
1010
} else {
1111
var mod = {
1212
exports: {}
1313
};
14-
factory(mod.exports, global.react);
14+
factory(mod.exports, global.react, global.invariant);
1515
global.timer = mod.exports;
1616
}
17-
})(this, function (exports, _react) {
17+
})(this, function (exports, _react, _invariant) {
1818
Object.defineProperty(exports, "__esModule", {
1919
value: true
2020
});
2121

2222
var _react2 = _interopRequireDefault(_react);
2323

24+
var _invariant2 = _interopRequireDefault(_invariant);
25+
2426
function _interopRequireDefault(obj) {
2527
return obj && obj.__esModule ? obj : {
2628
default: obj
@@ -90,6 +92,7 @@ function _typeof(obj) { return obj && typeof Symbol !== "undefined" && obj.const
9092
}
9193

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

131-
_this2.setTimeout();
134+
if (!_this2.stopped) _this2.setTimeout();
132135
}, delay);
133136
})
134137
}, {
135138
key: 'stop',
136139
value: function stop() {
140+
this.stopped = true;
137141
clearTimeout(this.timer);
138142
}
139143
}, {
140144
key: 'componentDidMount',
141145
value: function componentDidMount() {
146+
this.stopped = false;
142147
this.startTime = Date.now();
143148
this.setTimeout();
144149
}
@@ -150,9 +155,8 @@ function _typeof(obj) { return obj && typeof Symbol !== "undefined" && obj.const
150155
}, {
151156
key: 'render',
152157
value: function render() {
153-
var _props = this.props;
154-
var props = _props.props;
155-
var stop = _props.stop;
158+
var props = this.props;
159+
var stop = this.stop;
156160
var tick = this.state.tick;
157161
return _react2.default.createElement(TimedComponent, _extends({}, props, {
158162
tick: tick,

modules/timer.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import React from 'react';
2+
import invariant from 'invariant';
23

34
function timer(delay) {
45
invariant(
5-
typeof delay !== 'number' || delay === 0 || delay < 0,
6+
typeof delay === 'number' && delay > 0,
67
'[react-timer-hoc] `delay` should be a number greater than 0.'
78
);
89

@@ -19,15 +20,17 @@ function timer(delay) {
1920
const duration = delay - (this.startTime - Date.now()) % delay;
2021
this.timer = setTimeout(() => {
2122
this.setState({ tick: this.state.tick + 1 });
22-
this.setTimeout();
23+
if (!this.stopped) this.setTimeout();
2324
}, delay);
2425
}
2526

2627
stop() {
28+
this.stopped = true;
2729
clearTimeout(this.timer);
2830
}
2931

3032
componentDidMount() {
33+
this.stopped = false;
3134
this.startTime = Date.now();
3235
this.setTimeout();
3336
}

0 commit comments

Comments
 (0)