Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions spec/helpers/testScheduler-ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,42 @@ const commonInterface = require('mocha/lib/interfaces/common');
const escapeRe = require('escape-string-regexp');
//tslint:enable:no-var-requires no-require-imports

/** Polyfill requestAnimationFrame for testing animationFrame scheduler in Node */
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating

// requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel

// MIT license

(function(this: any, window: any) {
window = window || this;
let lastTime = 0;
const vendors = ['ms', 'moz', 'webkit', 'o'];
for (let x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame'];
window.cancelAnimationFrame = window[vendors[x] + 'CancelAnimationFrame']
|| window[vendors[x] + 'CancelRequestAnimationFrame'];
}

if (!window.requestAnimationFrame) {
window.requestAnimationFrame = (callback: Function, element: any) => {
const currTime = new Date().getTime();
const timeToCall = Math.max(0, 16 - (currTime - lastTime));
const id = window.setTimeout(() => { callback(currTime + timeToCall); },
timeToCall);
lastTime = currTime + timeToCall;
return id;
};
}

if (!window.cancelAnimationFrame) {
window.cancelAnimationFrame = (id: number) => {
clearTimeout(id);
};
}
}(global));

//setup sinon-chai
chai.use(sinonChai);

Expand Down
5 changes: 2 additions & 3 deletions src/internal/scheduler/AnimationFrameAction.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { AsyncAction } from './AsyncAction';
import { AnimationFrame } from '../util/AnimationFrame';
import { AnimationFrameScheduler } from './AnimationFrameScheduler';
import { Action } from './Action';

Expand All @@ -25,7 +24,7 @@ export class AnimationFrameAction<T> extends AsyncAction<T> {
// If an animation frame has already been requested, don't request another
// one. If an animation frame hasn't been requested yet, request one. Return
// the current animation frame request id.
return scheduler.scheduled || (scheduler.scheduled = AnimationFrame.requestAnimationFrame(
return scheduler.scheduled || (scheduler.scheduled = requestAnimationFrame(
() => scheduler.flush(null)));
}
protected recycleAsyncId(scheduler: AnimationFrameScheduler, id?: any, delay: number = 0): any {
Expand All @@ -39,7 +38,7 @@ export class AnimationFrameAction<T> extends AsyncAction<T> {
// set the scheduled flag to undefined so the next AnimationFrameAction will
// request its own.
if (scheduler.actions.length === 0) {
AnimationFrame.cancelAnimationFrame(id);
cancelAnimationFrame(id);
scheduler.scheduled = undefined;
}
// Return undefined so the action knows to request a new async id if it's rescheduled.
Expand Down
29 changes: 0 additions & 29 deletions src/internal/util/AnimationFrame.ts

This file was deleted.