Skip to content
This repository has been archived by the owner on Dec 6, 2024. It is now read-only.

Commit

Permalink
Release v4.5.0
Browse files Browse the repository at this point in the history
Cancel termination animation if Loading Bar should be restarted
  • Loading branch information
mironov committed Oct 20, 2019
1 parent 8781ae3 commit 832727c
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Release History

## 4.5.0
- Cancel termination animation if Loading Bar should be restarted

## 4.4.0
- Update react-redux peer dependency requirement (contributed by @hugomn)

Expand Down
8 changes: 8 additions & 0 deletions build/loading_bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ var LoadingBar = function (_Component) {
}, {
key: 'start',
value: function start() {
// There could be previous termination animation going, so we need to
// cancel it and forcefully reset the Loading Bar before starting
// the progress simulation from 0
if (this.terminatingAnimationTimeoutId) {
clearTimeout(this.terminatingAnimationTimeoutId);
this.reset();
}

var updateTime = this.props.updateTime;

this.progressIntervalId = setInterval(this.simulateProgress, updateTime);
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": "4.4.0",
"version": "4.5.0",
"description": "Simple Loading Bar for Redux and React",
"main": "build/index.js",
"typings": "index.d.ts",
Expand Down
15 changes: 15 additions & 0 deletions spec/loading_bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,21 @@ describe('LoadingBar', () => {
expect(wrapper.instance().progressIntervalId).toNotExist()
})

it('resets progress if loading becomes 0 and another progress '
+ 'started right away (loading > 0)', () => {
const wrapper = shallow(<LoadingBar />)
wrapper.setProps({ loading: 1 })
clock.tick(UPDATE_TIME)
expect(wrapper.state().percent).toBeGreaterThan(0).toBeLessThan(100)

wrapper.setProps({ loading: 0 })
expect(wrapper.state().percent).toBe(100)

wrapper.setProps({ loading: 1 })
expect(wrapper.instance().terminatingAnimationTimeoutId).toNotExist()
expect(wrapper.state().percent).toBe(0)
})

it('resets progress if loading becomes 0 and terminating animation '
+ 'finished', () => {
const wrapper = shallow(<LoadingBar />)
Expand Down
8 changes: 8 additions & 0 deletions src/loading_bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ class LoadingBar extends Component {
}

start() {
// There could be previous termination animation going, so we need to
// cancel it and forcefully reset the Loading Bar before starting
// the progress simulation from 0
if (this.terminatingAnimationTimeoutId) {
clearTimeout(this.terminatingAnimationTimeoutId)
this.reset()
}

const { updateTime } = this.props
this.progressIntervalId = setInterval(
this.simulateProgress,
Expand Down

0 comments on commit 832727c

Please sign in to comment.