Skip to content

Commit

Permalink
fix(AsapScheduler): Fix issue where canceling an asap or animationFra…
Browse files Browse the repository at this point in the history
…me action early could throw
  • Loading branch information
trxcllnt committed Jun 3, 2017
1 parent a7af560 commit f20bc89
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
15 changes: 15 additions & 0 deletions spec/schedulers/AnimationFrameScheduler-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ describe('Scheduler.animationFrame', () => {
sandbox.restore();
});

it('should cancel animationFrame actions when delay > 0', () => {
let actionHappened = false;
const sandbox = sinon.sandbox.create();
const fakeTimer = sandbox.useFakeTimers();
animationFrame.schedule(() => {
actionHappened = true;
}, 50).unsubscribe();
expect(actionHappened).to.be.false;
fakeTimer.tick(25);
expect(actionHappened).to.be.false;
fakeTimer.tick(25);
expect(actionHappened).to.be.false;
sandbox.restore();
});

it('should schedule an action to happen later', (done: MochaDone) => {
let actionHappened = false;
animationFrame.schedule(() => {
Expand Down
15 changes: 15 additions & 0 deletions spec/schedulers/AsapScheduler-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ describe('Scheduler.asap', () => {
sandbox.restore();
});

it('should cancel asap actions when delay > 0', () => {
let actionHappened = false;
const sandbox = sinon.sandbox.create();
const fakeTimer = sandbox.useFakeTimers();
asap.schedule(() => {
actionHappened = true;
}, 50).unsubscribe();
expect(actionHappened).to.be.false;
fakeTimer.tick(25);
expect(actionHappened).to.be.false;
fakeTimer.tick(25);
expect(actionHappened).to.be.false;
sandbox.restore();
});

it('should schedule an action to happen later', (done: MochaDone) => {
let actionHappened = false;
asap.schedule(() => {
Expand Down
3 changes: 2 additions & 1 deletion src/scheduler/AsyncAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ export class AsyncAction<T> extends Action<T> {
const index = actions.indexOf(this);

this.work = null;
this.delay = null;
this.state = null;
this.pending = false;
this.scheduler = null;
Expand All @@ -149,5 +148,7 @@ export class AsyncAction<T> extends Action<T> {
if (id != null) {
this.id = this.recycleAsyncId(scheduler, id, null);
}

this.delay = null;
}
}

0 comments on commit f20bc89

Please sign in to comment.