Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't execute rescheduled animation frame and asap actions in flush #5399

Merged
merged 4 commits into from Apr 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 28 additions & 0 deletions spec/schedulers/AnimationFrameScheduler-spec.ts
Expand Up @@ -115,4 +115,32 @@ describe('Scheduler.animationFrame', () => {
firstSubscription.unsubscribe();
}
});

it('should not execute rescheduled actions when flushing', (done: MochaDone) => {
let flushCount = 0;
let scheduledIndices: number[] = [];

let originalFlush = animationFrame.flush;
animationFrame.flush = (...args) => {
++flushCount;
originalFlush.apply(animationFrame, args);
if (flushCount === 2) {
animationFrame.flush = originalFlush;
try {
expect(scheduledIndices).to.deep.equal([0, 1]);
done();
} catch (error) {
done(error);
}
}
};

animationFrame.schedule(function (index) {
if (flushCount < 2) {
this.schedule(index! + 1);
scheduledIndices.push(index! + 1);
}
}, 0, 0);
scheduledIndices.push(0);
});
});
28 changes: 28 additions & 0 deletions spec/schedulers/AsapScheduler-spec.ts
Expand Up @@ -170,4 +170,32 @@ describe('Scheduler.asap', () => {
firstSubscription.unsubscribe();
}
});

it('should not execute rescheduled actions when flushing', (done: MochaDone) => {
let flushCount = 0;
let scheduledIndices: number[] = [];

let originalFlush = asap.flush;
asap.flush = (...args) => {
++flushCount;
originalFlush.apply(asap, args);
if (flushCount === 2) {
asap.flush = originalFlush;
try {
expect(scheduledIndices).to.deep.equal([0, 1]);
done();
} catch (error) {
done(error);
}
}
};

asap.schedule(function (index) {
if (flushCount < 2) {
this.schedule(index! + 1);
scheduledIndices.push(index! + 1);
}
}, 0, 0);
scheduledIndices.push(0);
});
});
2 changes: 1 addition & 1 deletion src/internal/scheduler/AnimationFrameScheduler.ts
Expand Up @@ -10,8 +10,8 @@ export class AnimationFrameScheduler extends AsyncScheduler {
const {actions} = this;
let error: any;
let index: number = -1;
let count: number = actions.length;
action = action || actions.shift()!;
let count: number = actions.length;

do {
if (error = action.execute(action.state, action.delay)) {
Expand Down
2 changes: 1 addition & 1 deletion src/internal/scheduler/AsapScheduler.ts
Expand Up @@ -10,8 +10,8 @@ export class AsapScheduler extends AsyncScheduler {
const {actions} = this;
let error: any;
let index: number = -1;
let count: number = actions.length;
action = action || actions.shift()!;
let count: number = actions.length;

do {
if (error = action.execute(action.state, action.delay)) {
Expand Down