Skip to content

Commit a49b3e0

Browse files
author
Minh Tran
committed
Version 0.2.3
1 parent 378f1bf commit a49b3e0

File tree

6 files changed

+61
-49
lines changed

6 files changed

+61
-49
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-progress-bar-plus",
3-
"version": "0.2.2",
3+
"version": "0.2.3",
44
"description": "Progress bar component for ReactJS.",
55
"main": ["dist/progress-bar.css", "dist/react-progress-bar-plus.js"],
66
"keywords": [

dist/react-progress-bar-plus.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/app/components/pages/Example1/Example1.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import ProgressBar from 'react-progress-bar-plus';
44
class Example1 extends React.Component {
55
state = {
66
percent: -1,
7-
autoIncrement: false,
87
intervalTime: 200
98
};
109

@@ -19,7 +18,6 @@ class Example1 extends React.Component {
1918
start = () => {
2019
this.setState({
2120
percent: 0,
22-
autoIncrement: true,
2321
intervalTime: (Math.random() * 1000)
2422
});
2523
};
@@ -28,7 +26,7 @@ class Example1 extends React.Component {
2826
return (
2927
<div>
3028
<ProgressBar percent={this.state.percent}
31-
autoIncrement={this.state.autoIncrement}
29+
autoIncrement={true}
3230
intervalTime={this.state.intervalTime}/>
3331

3432
<div className='text-center'>

lib/ProgressBar.js

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -44,28 +44,12 @@ var ProgressBar = (function (_React$Component) {
4444
});
4545
};
4646

47-
this.componentWillUnmount = function () {
48-
if (_this.interval) {
49-
clearInterval(_this.interval);
50-
}
51-
if (_this.timeout) {
52-
clearTimeout(_this.timeout);
47+
this.handleProps = function (props) {
48+
if (props.autoIncrement && props.percent >= 0 && props.percent < 99) {
49+
_this.interval = setInterval(_this.increment, props.intervalTime);
5350
}
54-
};
5551

56-
this.componentWillReceiveProps = function (nextProps) {
57-
if (_this.interval) {
58-
clearInterval(_this.interval);
59-
}
60-
if (_this.timeout) {
61-
clearTimeout(_this.timeout);
62-
}
63-
64-
if (nextProps.autoIncrement && nextProps.percent >= 0 && nextProps.percent < 99) {
65-
_this.interval = setInterval(_this.increment, nextProps.intervalTime);
66-
}
67-
68-
if (nextProps.percent >= 100) {
52+
if (props.percent >= 100) {
6953
_this.setState({
7054
percent: 99.9
7155
}, function () {
@@ -77,10 +61,33 @@ var ProgressBar = (function (_React$Component) {
7761
});
7862
} else {
7963
_this.setState({
80-
percent: nextProps.percent
64+
percent: props.percent
8165
});
8266
}
8367
};
68+
69+
this.componentDidMount = function () {
70+
_this.handleProps(_this.props);
71+
};
72+
73+
this.componentWillReceiveProps = function (nextProps) {
74+
if (_this.interval) {
75+
clearInterval(_this.interval);
76+
}
77+
if (_this.timeout) {
78+
clearTimeout(_this.timeout);
79+
}
80+
_this.handleProps(nextProps);
81+
};
82+
83+
this.componentWillUnmount = function () {
84+
if (_this.interval) {
85+
clearInterval(_this.interval);
86+
}
87+
if (_this.timeout) {
88+
clearTimeout(_this.timeout);
89+
}
90+
};
8491
}
8592

8693
_createClass(ProgressBar, [{

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-progress-bar-plus",
3-
"version": "0.2.2",
3+
"version": "0.2.3",
44
"description": "Progress bar component for ReactJS.",
55
"main": "lib/index.js",
66
"scripts": {

src/ProgressBar.js

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,12 @@ class ProgressBar extends React.Component {
2828
});
2929
};
3030

31-
componentWillUnmount = () => {
32-
if (this.interval) {
33-
clearInterval(this.interval);
34-
}
35-
if (this.timeout) {
36-
clearTimeout(this.timeout);
31+
handleProps = (props) => {
32+
if (props.autoIncrement && props.percent >= 0 && props.percent < 99) {
33+
this.interval = setInterval(this.increment, props.intervalTime);
3734
}
38-
};
3935

40-
componentWillReceiveProps = (nextProps) => {
41-
if (this.interval) {
42-
clearInterval(this.interval);
43-
}
44-
if (this.timeout) {
45-
clearTimeout(this.timeout);
46-
}
47-
48-
if (nextProps.autoIncrement && nextProps.percent >= 0 && nextProps.percent < 99) {
49-
this.interval = setInterval(this.increment, nextProps.intervalTime);
50-
}
51-
52-
if (nextProps.percent >= 100) {
36+
if (props.percent >= 100) {
5337
this.setState({
5438
percent: 99.9
5539
}, () => {
@@ -61,11 +45,34 @@ class ProgressBar extends React.Component {
6145
});
6246
} else {
6347
this.setState({
64-
percent: nextProps.percent
48+
percent: props.percent
6549
});
6650
}
6751
};
6852

53+
componentDidMount = () => {
54+
this.handleProps(this.props);
55+
};
56+
57+
componentWillReceiveProps = (nextProps) => {
58+
if (this.interval) {
59+
clearInterval(this.interval);
60+
}
61+
if (this.timeout) {
62+
clearTimeout(this.timeout);
63+
}
64+
this.handleProps(nextProps);
65+
};
66+
67+
componentWillUnmount = () => {
68+
if (this.interval) {
69+
clearInterval(this.interval);
70+
}
71+
if (this.timeout) {
72+
clearTimeout(this.timeout);
73+
}
74+
};
75+
6976
render() {
7077
let className = ClassNames({
7178
'react-progress-bar': true,

0 commit comments

Comments
 (0)