timer-countdown
Advanced tools
Comparing version 0.0.7 to 0.0.8
@@ -52,9 +52,8 @@ "use strict"; | ||
_classCallCheck(_this, CountdownTimer); | ||
_classCallCheck(this, CountdownTimer); | ||
_this = _possibleConstructorReturn(_this, _getPrototypeOf(CountdownTimer).call(_this, props)); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(CountdownTimer).call(this, props)); | ||
_this.state = { | ||
timeRemaining: this.props.timeLeft, | ||
interval:1000, | ||
prevTime: null | ||
}; | ||
@@ -68,4 +67,4 @@ return _this; | ||
is_mounted = true; | ||
_this.startTimer(); | ||
_this.interval = setInterval(_this.startTimer.bind(_this), 1000); | ||
this.startTimer(); | ||
this.interval = setInterval(this.startTimer.bind(this), 1000); | ||
} | ||
@@ -75,3 +74,3 @@ }, { | ||
value: function componentWillUnmount() { | ||
clearInterval(_this.interval); | ||
clearInterval(this.interval); | ||
} | ||
@@ -82,4 +81,5 @@ }, { | ||
const currentTime = Date.now(); | ||
const differenceInTime = _this.state.prevTime ? (currentTime - _this.state.prevTime) : 0; | ||
const interval = _this.props.interval; | ||
console.log(this.state); | ||
const differenceInTime = this.state.prevTime ? (currentTime - this.state.prevTime) : 0; | ||
const interval = this.props.interval; | ||
const timeRemainingInInterval = interval - (differenceInTime % interval) | ||
@@ -90,7 +90,7 @@ let timeout = timeRemainingInInterval; | ||
} | ||
const timeRemaining = Math.max(_this.state.timeRemaining - differenceInTime, 0); | ||
const countdownComplete = (_this.state.prevTime && timeRemaining <= 0); | ||
const timeRemaining = Math.max(this.state.timeRemaining - differenceInTime, 0); | ||
const countdownComplete = (this.state.prevTime && timeRemaining <= 0); | ||
if (is_mounted) { | ||
_this.setState({ | ||
timeoutId: countdownComplete? null : setInterval(_this.startTimer, timeout), | ||
this.setState({ | ||
timeoutId: countdownComplete? null : setInterval(this.startTimer, timeout), | ||
prevTime: currentTime, | ||
@@ -100,8 +100,8 @@ timeRemaining: timeRemaining | ||
} | ||
if (countdownComplete && _this.props.completeCallback) { | ||
_this.props.completeCallback(); | ||
_this.componentWillUnmount(); | ||
if (countdownComplete && this.props.completeCallback) { | ||
this.props.completeCallback(); | ||
this.componentWillUnmount(); | ||
} | ||
if (_this.props.tickCallback) { | ||
_this.props.tickCallback(timeRemaining); | ||
if (this.props.tickCallback) { | ||
this.props.tickCallback(timeRemaining); | ||
} | ||
@@ -130,3 +130,3 @@ }, | ||
}, _react.default.createElement("div", { | ||
}, " ", _this.getFormattedTime(_this.state.timeRemaining))); | ||
}, " ", this.getFormattedTime(this.state.timeRemaining))); | ||
} | ||
@@ -133,0 +133,0 @@ }]); |
{ | ||
"name": "timer-countdown", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"description": "A well designed ReactJs component for timer-counter", | ||
@@ -5,0 +5,0 @@ "main": "lib/CountdownTimer.js", |
9478