Skip to content

Commit

Permalink
Release v2.7.4
Browse files Browse the repository at this point in the history
Do not set second interval if loading bar is shown
  • Loading branch information
mironov committed Mar 19, 2017
1 parent 960db4b commit b958e75
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Release History

## 2.7.4
- Do not set second interval if loading bar is shown

## 2.7.3
- Fix race condition when `showLoading` is called right after `hideLoading`

Expand Down
8 changes: 6 additions & 2 deletions build/loading_bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,16 @@ var LoadingBar = exports.LoadingBar = function (_React$Component) {
var loadingBarNotShown = !progressInterval;
var endingAnimationGoing = percent === 100;

if (loadingBarNotShown || endingAnimationGoing) {
if (loadingBarNotShown) {
progressInterval = setInterval(this.boundSimulateProgress, this.props.updateTime);
}

if (endingAnimationGoing) {
clearTimeout(endingAnimationTimeout);
percent = 0;
}

percent = 0;

this.setState({ progressInterval: progressInterval, percent: percent });
}
}, {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-redux-loading-bar",
"version": "2.7.3",
"version": "2.7.4",
"description": "Simple Loading Bar for Redux and React",
"main": "build/index.js",
"typings": "index.d.ts",
Expand Down
10 changes: 10 additions & 0 deletions spec/loading_bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,16 @@ describe('LoadingBar', () => {
expect(spySimulateProgress).toHaveBeenCalled()
expect(spySimulateProgress.calls.length).toEqual(2)
})

it('does not set second interval if loading bar is shown', () => {
const wrapper = shallow(<LoadingBar />)
wrapper.setProps({ loading: 1 })
const intervalId = wrapper.state().progressInterval
wrapper.setProps({ loading: 0 })
expect(wrapper.state().percent).toBe(100)
wrapper.setProps({ loading: 1 })
expect(wrapper.state().progressInterval).toEqual(intervalId)
})
})

describe('#simulateProgress', () => {
Expand Down
8 changes: 6 additions & 2 deletions src/loading_bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,19 @@ export class LoadingBar extends React.Component {
const loadingBarNotShown = !progressInterval
const endingAnimationGoing = percent === 100

if (loadingBarNotShown || endingAnimationGoing) {
if (loadingBarNotShown) {
progressInterval = setInterval(
this.boundSimulateProgress,
this.props.updateTime,
)
}

if (endingAnimationGoing) {
clearTimeout(endingAnimationTimeout)
percent = 0
}

percent = 0

this.setState({ progressInterval, percent })
}

Expand Down

0 comments on commit b958e75

Please sign in to comment.