@khanacademy/wonder-blocks-timing
Advanced tools
Comparing version 1.0.4 to 1.1.0
@@ -380,3 +380,3 @@ import { Component, createElement } from 'react'; | ||
* | ||
* @param {() => mixed} action The action to be invoked. | ||
* @param {DOMHighResTimeStamp => mixed} action The action to be invoked. | ||
* @param {boolean} [autoSchedule] When true, the request is made immediately on | ||
@@ -432,4 +432,4 @@ * instanstiation; otherwise, `set` must be called to make the request. | ||
this._animationFrameId = requestAnimationFrame(function () { | ||
return _this.clear(true); | ||
this._animationFrameId = requestAnimationFrame(function (time) { | ||
return _this.clear(true, time); | ||
}); | ||
@@ -453,3 +453,3 @@ } | ||
key: "clear", | ||
value: function clear(resolve) { | ||
value: function clear(resolve, time) { | ||
var animationFrameId = this._animationFrameId; | ||
@@ -465,3 +465,3 @@ this._animationFrameId = null; | ||
if (resolve) { | ||
this._action(); | ||
this._action(time || performance.now()); | ||
} | ||
@@ -468,0 +468,0 @@ } |
@@ -388,3 +388,3 @@ module.exports = | ||
* | ||
* @param {() => mixed} action The action to be invoked. | ||
* @param {DOMHighResTimeStamp => mixed} action The action to be invoked. | ||
* @param {boolean} [autoSchedule] When true, the request is made immediately on | ||
@@ -440,4 +440,4 @@ * instanstiation; otherwise, `set` must be called to make the request. | ||
this._animationFrameId = requestAnimationFrame(function () { | ||
return _this.clear(true); | ||
this._animationFrameId = requestAnimationFrame(function (time) { | ||
return _this.clear(true, time); | ||
}); | ||
@@ -461,3 +461,3 @@ } | ||
key: "clear", | ||
value: function clear(resolve) { | ||
value: function clear(resolve, time) { | ||
var animationFrameId = this._animationFrameId; | ||
@@ -473,3 +473,3 @@ this._animationFrameId = null; | ||
if (resolve) { | ||
this._action(); | ||
this._action(time || performance.now()); | ||
} | ||
@@ -476,0 +476,0 @@ } |
{ | ||
"name": "@khanacademy/wonder-blocks-timing", | ||
"private": false, | ||
"version": "1.0.4", | ||
"version": "1.1.0", | ||
"design": "v1", | ||
@@ -24,3 +24,3 @@ "publishConfig": { | ||
"license": "MIT", | ||
"gitHead": "e80922dd847385d5b3baa19250a29188e4a6b353" | ||
"gitHead": "4b4345202ae71309a9d3aaa20c75eb30e194ccfe" | ||
} |
@@ -45,3 +45,3 @@ // @flow | ||
animationFrame( | ||
action: () => void, | ||
action: (DOMHighResTimeStamp) => void, | ||
autoSchedule?: boolean, | ||
@@ -48,0 +48,0 @@ resolveOnClear?: boolean, |
@@ -15,3 +15,3 @@ // @flow | ||
_animationFrameId: ?AnimationFrameID; | ||
_action: () => mixed; | ||
_action: (DOMHighResTimeStamp) => mixed; | ||
@@ -22,3 +22,3 @@ /** | ||
* | ||
* @param {() => mixed} action The action to be invoked. | ||
* @param {DOMHighResTimeStamp => mixed} action The action to be invoked. | ||
* @param {boolean} [autoSchedule] When true, the request is made immediately on | ||
@@ -29,3 +29,6 @@ * instanstiation; otherwise, `set` must be called to make the request. | ||
*/ | ||
constructor(action: () => mixed, autoSchedule?: boolean) { | ||
constructor( | ||
action: (DOMHighResTimeStamp) => mixed, | ||
autoSchedule?: boolean, | ||
) { | ||
if (typeof action !== "function") { | ||
@@ -66,3 +69,5 @@ throw new Error("Action must be a function"); | ||
} | ||
this._animationFrameId = requestAnimationFrame(() => this.clear(true)); | ||
this._animationFrameId = requestAnimationFrame((time) => | ||
this.clear(true, time), | ||
); | ||
} | ||
@@ -83,3 +88,3 @@ | ||
*/ | ||
clear(resolve?: boolean): void { | ||
clear(resolve?: boolean, time?: DOMHighResTimeStamp): void { | ||
const animationFrameId = this._animationFrameId; | ||
@@ -92,5 +97,5 @@ this._animationFrameId = null; | ||
if (resolve) { | ||
this._action(); | ||
this._action(time || performance.now()); | ||
} | ||
} | ||
} |
@@ -116,3 +116,3 @@ // @flow | ||
const action = jest.fn(); | ||
const animationFrame = new AnimationFrame(() => action()); | ||
const animationFrame = new AnimationFrame((time) => action(time)); | ||
animationFrame.set(); | ||
@@ -123,6 +123,7 @@ // Flow doesn't know we added jest mocks to this $FlowFixMe | ||
// Act | ||
scheduledAction(); | ||
scheduledAction(2001); | ||
// Assert | ||
expect(action).toHaveBeenCalledTimes(1); | ||
expect(action).toHaveBeenCalledWith(2001); | ||
}); | ||
@@ -176,2 +177,3 @@ | ||
// Arrange | ||
jest.spyOn(performance, "now").mockReturnValue(42); | ||
const action = jest.fn(); | ||
@@ -187,2 +189,3 @@ const animationFrame = new AnimationFrame(action); | ||
expect(action).toHaveBeenCalledTimes(1); | ||
expect(action).toHaveBeenCalledWith(42); | ||
}); | ||
@@ -189,0 +192,0 @@ |
@@ -206,3 +206,3 @@ // @flow | ||
* | ||
* @param {() => void} action The action to be invoked before the repaint. | ||
* @param {DOMHighResTimeStamp => void} action The action to be invoked before the repaint. | ||
* @param {boolean} [autoSchedule] Whether or not to make the request as soon | ||
@@ -219,3 +219,3 @@ * as this call is made, or wait until `set` is explicitly called. Defaults | ||
animationFrame( | ||
action: () => void, | ||
action: (time: DOMHighResTimeStamp) => void, | ||
autoSchedule?: boolean, | ||
@@ -222,0 +222,0 @@ resolveOnClear?: boolean, |
120603
2657