Comparing version 5.3.0 to 6.0.0-rc.1
@@ -5,26 +5,20 @@ 'use strict'; | ||
var defaultTimestep = (1 / 60) * 1000; | ||
var getCurrentTime = typeof performance !== "undefined" | ||
? function () { return performance.now(); } | ||
: function () { return Date.now(); }; | ||
var onNextFrame = typeof window !== "undefined" | ||
? function (callback) { | ||
return window.requestAnimationFrame(callback); | ||
} | ||
: function (callback) { | ||
return setTimeout(function () { return callback(getCurrentTime()); }, defaultTimestep); | ||
}; | ||
const defaultTimestep = (1 / 60) * 1000; | ||
const getCurrentTime = typeof performance !== "undefined" | ||
? () => performance.now() | ||
: () => Date.now(); | ||
const onNextFrame = typeof window !== "undefined" | ||
? (callback) => window.requestAnimationFrame(callback) | ||
: (callback) => setTimeout(() => callback(getCurrentTime()), defaultTimestep); | ||
function createRenderStep(runNextFrame) { | ||
var toRun = []; | ||
var toRunNextFrame = []; | ||
var numToRun = 0; | ||
var isProcessing = false; | ||
var toKeepAlive = new WeakSet(); | ||
var step = { | ||
schedule: function (callback, keepAlive, immediate) { | ||
if (keepAlive === void 0) { keepAlive = false; } | ||
if (immediate === void 0) { immediate = false; } | ||
var addToCurrentFrame = immediate && isProcessing; | ||
var buffer = addToCurrentFrame ? toRun : toRunNextFrame; | ||
let toRun = []; | ||
let toRunNextFrame = []; | ||
let numToRun = 0; | ||
let isProcessing = false; | ||
const toKeepAlive = new WeakSet(); | ||
const step = { | ||
schedule: (callback, keepAlive = false, immediate = false) => { | ||
const addToCurrentFrame = immediate && isProcessing; | ||
const buffer = addToCurrentFrame ? toRun : toRunNextFrame; | ||
if (keepAlive) | ||
@@ -39,4 +33,4 @@ toKeepAlive.add(callback); | ||
}, | ||
cancel: function (callback) { | ||
var index = toRunNextFrame.indexOf(callback); | ||
cancel: (callback) => { | ||
const index = toRunNextFrame.indexOf(callback); | ||
if (index !== -1) | ||
@@ -46,11 +40,10 @@ toRunNextFrame.splice(index, 1); | ||
}, | ||
process: function (frameData) { | ||
var _a; | ||
process: (frameData) => { | ||
isProcessing = true; | ||
_a = [toRunNextFrame, toRun], toRun = _a[0], toRunNextFrame = _a[1]; | ||
[toRun, toRunNextFrame] = [toRunNextFrame, toRun]; | ||
toRunNextFrame.length = 0; | ||
numToRun = toRun.length; | ||
if (numToRun) { | ||
for (var i = 0; i < numToRun; i++) { | ||
var callback = toRun[i]; | ||
for (let i = 0; i < numToRun; i++) { | ||
const callback = toRun[i]; | ||
callback(frameData); | ||
@@ -69,11 +62,11 @@ if (toKeepAlive.has(callback)) { | ||
var maxElapsed = 40; | ||
var useDefaultElapsed = true; | ||
var runNextFrame = false; | ||
var isProcessing = false; | ||
var frame = { | ||
const maxElapsed = 40; | ||
let useDefaultElapsed = true; | ||
let runNextFrame = false; | ||
let isProcessing = false; | ||
const frame = { | ||
delta: 0, | ||
timestamp: 0, | ||
}; | ||
var stepsOrder = [ | ||
const stepsOrder = [ | ||
"read", | ||
@@ -85,11 +78,9 @@ "update", | ||
]; | ||
var steps = stepsOrder.reduce(function (acc, key) { | ||
acc[key] = createRenderStep(function () { return (runNextFrame = true); }); | ||
const steps = stepsOrder.reduce((acc, key) => { | ||
acc[key] = createRenderStep(() => (runNextFrame = true)); | ||
return acc; | ||
}, {}); | ||
var sync = stepsOrder.reduce(function (acc, key) { | ||
var step = steps[key]; | ||
acc[key] = function (process, keepAlive, immediate) { | ||
if (keepAlive === void 0) { keepAlive = false; } | ||
if (immediate === void 0) { immediate = false; } | ||
const sync = stepsOrder.reduce((acc, key) => { | ||
const step = steps[key]; | ||
acc[key] = (process, keepAlive = false, immediate = false) => { | ||
if (!runNextFrame) | ||
@@ -101,12 +92,12 @@ startLoop(); | ||
}, {}); | ||
var cancelSync = stepsOrder.reduce(function (acc, key) { | ||
const cancelSync = stepsOrder.reduce((acc, key) => { | ||
acc[key] = steps[key].cancel; | ||
return acc; | ||
}, {}); | ||
var flushSync = stepsOrder.reduce(function (acc, key) { | ||
acc[key] = function () { return steps[key].process(frame); }; | ||
const flushSync = stepsOrder.reduce((acc, key) => { | ||
acc[key] = () => steps[key].process(frame); | ||
return acc; | ||
}, {}); | ||
var processStep = function (stepId) { return steps[stepId].process(frame); }; | ||
var processFrame = function (timestamp) { | ||
const processStep = (stepId) => steps[stepId].process(frame); | ||
const processFrame = (timestamp) => { | ||
runNextFrame = false; | ||
@@ -125,3 +116,3 @@ frame.delta = useDefaultElapsed | ||
}; | ||
var startLoop = function () { | ||
const startLoop = () => { | ||
runNextFrame = true; | ||
@@ -132,3 +123,3 @@ useDefaultElapsed = true; | ||
}; | ||
var getFrameData = function () { return frame; }; | ||
const getFrameData = () => frame; | ||
@@ -135,0 +126,0 @@ exports.cancelSync = cancelSync; |
@@ -7,26 +7,20 @@ (function (global, factory) { | ||
var defaultTimestep = (1 / 60) * 1000; | ||
var getCurrentTime = typeof performance !== "undefined" | ||
? function () { return performance.now(); } | ||
: function () { return Date.now(); }; | ||
var onNextFrame = typeof window !== "undefined" | ||
? function (callback) { | ||
return window.requestAnimationFrame(callback); | ||
} | ||
: function (callback) { | ||
return setTimeout(function () { return callback(getCurrentTime()); }, defaultTimestep); | ||
}; | ||
const defaultTimestep = (1 / 60) * 1000; | ||
const getCurrentTime = typeof performance !== "undefined" | ||
? () => performance.now() | ||
: () => Date.now(); | ||
const onNextFrame = typeof window !== "undefined" | ||
? (callback) => window.requestAnimationFrame(callback) | ||
: (callback) => setTimeout(() => callback(getCurrentTime()), defaultTimestep); | ||
function createRenderStep(runNextFrame) { | ||
var toRun = []; | ||
var toRunNextFrame = []; | ||
var numToRun = 0; | ||
var isProcessing = false; | ||
var toKeepAlive = new WeakSet(); | ||
var step = { | ||
schedule: function (callback, keepAlive, immediate) { | ||
if (keepAlive === void 0) { keepAlive = false; } | ||
if (immediate === void 0) { immediate = false; } | ||
var addToCurrentFrame = immediate && isProcessing; | ||
var buffer = addToCurrentFrame ? toRun : toRunNextFrame; | ||
let toRun = []; | ||
let toRunNextFrame = []; | ||
let numToRun = 0; | ||
let isProcessing = false; | ||
const toKeepAlive = new WeakSet(); | ||
const step = { | ||
schedule: (callback, keepAlive = false, immediate = false) => { | ||
const addToCurrentFrame = immediate && isProcessing; | ||
const buffer = addToCurrentFrame ? toRun : toRunNextFrame; | ||
if (keepAlive) | ||
@@ -41,4 +35,4 @@ toKeepAlive.add(callback); | ||
}, | ||
cancel: function (callback) { | ||
var index = toRunNextFrame.indexOf(callback); | ||
cancel: (callback) => { | ||
const index = toRunNextFrame.indexOf(callback); | ||
if (index !== -1) | ||
@@ -48,11 +42,10 @@ toRunNextFrame.splice(index, 1); | ||
}, | ||
process: function (frameData) { | ||
var _a; | ||
process: (frameData) => { | ||
isProcessing = true; | ||
_a = [toRunNextFrame, toRun], toRun = _a[0], toRunNextFrame = _a[1]; | ||
[toRun, toRunNextFrame] = [toRunNextFrame, toRun]; | ||
toRunNextFrame.length = 0; | ||
numToRun = toRun.length; | ||
if (numToRun) { | ||
for (var i = 0; i < numToRun; i++) { | ||
var callback = toRun[i]; | ||
for (let i = 0; i < numToRun; i++) { | ||
const callback = toRun[i]; | ||
callback(frameData); | ||
@@ -71,11 +64,11 @@ if (toKeepAlive.has(callback)) { | ||
var maxElapsed = 40; | ||
var useDefaultElapsed = true; | ||
var runNextFrame = false; | ||
var isProcessing = false; | ||
var frame = { | ||
const maxElapsed = 40; | ||
let useDefaultElapsed = true; | ||
let runNextFrame = false; | ||
let isProcessing = false; | ||
const frame = { | ||
delta: 0, | ||
timestamp: 0, | ||
}; | ||
var stepsOrder = [ | ||
const stepsOrder = [ | ||
"read", | ||
@@ -87,11 +80,9 @@ "update", | ||
]; | ||
var steps = stepsOrder.reduce(function (acc, key) { | ||
acc[key] = createRenderStep(function () { return (runNextFrame = true); }); | ||
const steps = stepsOrder.reduce((acc, key) => { | ||
acc[key] = createRenderStep(() => (runNextFrame = true)); | ||
return acc; | ||
}, {}); | ||
var sync = stepsOrder.reduce(function (acc, key) { | ||
var step = steps[key]; | ||
acc[key] = function (process, keepAlive, immediate) { | ||
if (keepAlive === void 0) { keepAlive = false; } | ||
if (immediate === void 0) { immediate = false; } | ||
const sync = stepsOrder.reduce((acc, key) => { | ||
const step = steps[key]; | ||
acc[key] = (process, keepAlive = false, immediate = false) => { | ||
if (!runNextFrame) | ||
@@ -103,12 +94,12 @@ startLoop(); | ||
}, {}); | ||
var cancelSync = stepsOrder.reduce(function (acc, key) { | ||
const cancelSync = stepsOrder.reduce((acc, key) => { | ||
acc[key] = steps[key].cancel; | ||
return acc; | ||
}, {}); | ||
var flushSync = stepsOrder.reduce(function (acc, key) { | ||
acc[key] = function () { return steps[key].process(frame); }; | ||
const flushSync = stepsOrder.reduce((acc, key) => { | ||
acc[key] = () => steps[key].process(frame); | ||
return acc; | ||
}, {}); | ||
var processStep = function (stepId) { return steps[stepId].process(frame); }; | ||
var processFrame = function (timestamp) { | ||
const processStep = (stepId) => steps[stepId].process(frame); | ||
const processFrame = (timestamp) => { | ||
runNextFrame = false; | ||
@@ -127,3 +118,3 @@ frame.delta = useDefaultElapsed | ||
}; | ||
var startLoop = function () { | ||
const startLoop = () => { | ||
runNextFrame = true; | ||
@@ -134,3 +125,3 @@ useDefaultElapsed = true; | ||
}; | ||
var getFrameData = function () { return frame; }; | ||
const getFrameData = () => frame; | ||
@@ -137,0 +128,0 @@ exports.cancelSync = cancelSync; |
@@ -1,1 +0,1 @@ | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).framesync={})}(this,(function(e){"use strict";var n=1/60*1e3,t="undefined"!=typeof performance?function(){return performance.now()}:function(){return Date.now()},r="undefined"!=typeof window?function(e){return window.requestAnimationFrame(e)}:function(e){return setTimeout((function(){return e(t())}),n)};var u=!0,o=!1,i=!1,c={delta:0,timestamp:0},f=["read","update","preRender","render","postRender"],d=f.reduce((function(e,n){return e[n]=function(e){var n=[],t=[],r=0,u=!1,o=new WeakSet,i={schedule:function(e,i,c){void 0===i&&(i=!1),void 0===c&&(c=!1);var f=c&&u,d=f?n:t;return i&&o.add(e),-1===d.indexOf(e)&&(d.push(e),f&&u&&(r=n.length)),e},cancel:function(e){var n=t.indexOf(e);-1!==n&&t.splice(n,1),o.delete(e)},process:function(c){var f;if(u=!0,n=(f=[t,n])[0],(t=f[1]).length=0,r=n.length)for(var d=0;d<r;d++){var a=n[d];a(c),o.has(a)&&(i.schedule(a),e())}u=!1}};return i}((function(){return o=!0})),e}),{}),a=f.reduce((function(e,n){var t=d[n];return e[n]=function(e,n,r){return void 0===n&&(n=!1),void 0===r&&(r=!1),o||h(),t.schedule(e,n,r)},e}),{}),s=f.reduce((function(e,n){return e[n]=d[n].cancel,e}),{}),l=f.reduce((function(e,n){return e[n]=function(){return d[n].process(c)},e}),{}),p=function(e){return d[e].process(c)},m=function(e){o=!1,c.delta=u?n:Math.max(Math.min(e-c.timestamp,40),1),c.timestamp=e,i=!0,f.forEach(p),i=!1,o&&(u=!1,r(m))},h=function(){o=!0,u=!0,i||r(m)};e.cancelSync=s,e.default=a,e.flushSync=l,e.getFrameData=function(){return c},Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).framesync={})}(this,(function(e){"use strict";const t=1/60*1e3,n="undefined"!=typeof performance?()=>performance.now():()=>Date.now(),o="undefined"!=typeof window?e=>window.requestAnimationFrame(e):e=>setTimeout((()=>e(n())),t);let c=!0,d=!1,s=!1;const r={delta:0,timestamp:0},a=["read","update","preRender","render","postRender"],f=a.reduce(((e,t)=>(e[t]=function(e){let t=[],n=[],o=0,c=!1;const d=new WeakSet,s={schedule:(e,s=!1,r=!1)=>{const a=r&&c,f=a?t:n;return s&&d.add(e),-1===f.indexOf(e)&&(f.push(e),a&&c&&(o=t.length)),e},cancel:e=>{const t=n.indexOf(e);-1!==t&&n.splice(t,1),d.delete(e)},process:r=>{if(c=!0,[t,n]=[n,t],n.length=0,o=t.length,o)for(let n=0;n<o;n++){const o=t[n];o(r),d.has(o)&&(s.schedule(o),e())}c=!1}};return s}((()=>d=!0)),e)),{}),i=a.reduce(((e,t)=>{const n=f[t];return e[t]=(e,t=!1,o=!1)=>(d||h(),n.schedule(e,t,o)),e}),{}),u=a.reduce(((e,t)=>(e[t]=f[t].cancel,e)),{}),l=a.reduce(((e,t)=>(e[t]=()=>f[t].process(r),e)),{}),p=e=>f[e].process(r),m=e=>{d=!1,r.delta=c?t:Math.max(Math.min(e-r.timestamp,40),1),r.timestamp=e,s=!0,a.forEach(p),s=!1,d&&(c=!1,o(m))},h=()=>{d=!0,c=!0,s||o(m)};e.cancelSync=u,e.default=i,e.flushSync=l,e.getFrameData=()=>r,Object.defineProperty(e,"__esModule",{value:!0})})); |
import sync, { cancelSync } from "../"; | ||
import { onNextFrame } from "../on-next-frame"; | ||
describe("onNextFrame", function () { | ||
it("fires callback on following frame", function () { | ||
return new Promise(function (resolve) { return onNextFrame(resolve); }); | ||
describe("onNextFrame", () => { | ||
it("fires callback on following frame", () => { | ||
return new Promise((resolve) => onNextFrame(resolve)); | ||
}); | ||
}); | ||
describe("sync", function () { | ||
it("fires callbacks in the correct order", function () { | ||
return new Promise(function (resolve, reject) { | ||
var order = []; | ||
sync.read(function () { return order.push(0); }); | ||
sync.update(function () { return order.push(1); }); | ||
sync.preRender(function () { return order.push(2); }); | ||
sync.render(function () { return order.push(3); }); | ||
sync.postRender(function () { | ||
describe("sync", () => { | ||
it("fires callbacks in the correct order", () => { | ||
return new Promise((resolve, reject) => { | ||
const order = []; | ||
sync.read(() => order.push(0)); | ||
sync.update(() => order.push(1)); | ||
sync.preRender(() => order.push(2)); | ||
sync.render(() => order.push(3)); | ||
sync.postRender(() => { | ||
order.push(4); | ||
@@ -31,70 +31,62 @@ if (order[0] === 0 && | ||
}); | ||
it("cancels callbacks", function () { | ||
return new Promise(function (resolve, reject) { | ||
var hasFired = false; | ||
var process = sync.render(function () { return (hasFired = true); }); | ||
sync.update(function () { return cancelSync.render(process); }); | ||
sync.postRender(function () { return (hasFired ? reject(hasFired) : resolve()); }); | ||
it("cancels callbacks", () => { | ||
return new Promise((resolve, reject) => { | ||
let hasFired = false; | ||
const process = sync.render(() => (hasFired = true)); | ||
sync.update(() => cancelSync.render(process)); | ||
sync.postRender(() => (hasFired ? reject(hasFired) : resolve())); | ||
}); | ||
}); | ||
it("fires callback on current frame if scheduled with `true` within the same step", function () { | ||
return new Promise(function (resolve, reject) { | ||
var v = 0; | ||
sync.update(function (_a) { | ||
var prevTimestamp = _a.timestamp; | ||
it("fires callback on current frame if scheduled with `true` within the same step", () => { | ||
return new Promise((resolve, reject) => { | ||
let v = 0; | ||
sync.update(({ timestamp: prevTimestamp }) => { | ||
v++; | ||
sync.update(function (_a) { | ||
var timestamp = _a.timestamp; | ||
sync.update(({ timestamp }) => { | ||
v++; | ||
if (timestamp !== prevTimestamp) { | ||
reject(timestamp + " " + prevTimestamp); | ||
reject(`${timestamp} ${prevTimestamp}`); | ||
} | ||
}, false, true); | ||
}); | ||
sync.render(function () { return (v === 2 ? resolve() : reject(v)); }); | ||
sync.render(() => (v === 2 ? resolve() : reject(v))); | ||
}); | ||
}); | ||
it("fires callback on next frame if scheduled with `true` outside the same step", function () { | ||
return new Promise(function (resolve, reject) { | ||
var v = 0; | ||
sync.update(function () { return v++; }); | ||
sync.update(function () { return v++; }, false, true); | ||
sync.render(function () { return (v === 2 ? resolve() : reject()); }); | ||
it("fires callback on next frame if scheduled with `true` outside the same step", () => { | ||
return new Promise((resolve, reject) => { | ||
let v = 0; | ||
sync.update(() => v++); | ||
sync.update(() => v++, false, true); | ||
sync.render(() => (v === 2 ? resolve() : reject())); | ||
}); | ||
}); | ||
it("uses default elapsed time if first fire", function () { | ||
return new Promise(function (resolve, reject) { | ||
sync.update(function (_a) { | ||
var defaultElapsed = _a.delta; | ||
setTimeout(function () { | ||
return sync.update(function (_a) { | ||
var delta = _a.delta; | ||
return delta === defaultElapsed | ||
? resolve() | ||
: reject(defaultElapsed, delta); | ||
}); | ||
}, 50); | ||
it("uses default elapsed time if first fire", () => { | ||
return new Promise((resolve, reject) => { | ||
sync.update(({ delta: defaultElapsed }) => { | ||
setTimeout(() => sync.update(({ delta }) => delta === defaultElapsed | ||
? resolve() | ||
: reject(defaultElapsed, delta)), 50); | ||
}); | ||
}); | ||
}); | ||
it("correctly cancels", function () { | ||
return new Promise(function (resolve, reject) { | ||
var callback = function () { return reject(); }; | ||
sync.read(function () { return cancelSync.update(callback); }); | ||
it("correctly cancels", () => { | ||
return new Promise((resolve, reject) => { | ||
const callback = () => reject(); | ||
sync.read(() => cancelSync.update(callback)); | ||
sync.update(callback); | ||
sync.render(function () { return resolve(); }); | ||
sync.render(() => resolve()); | ||
}); | ||
}); | ||
it("correctly keeps alive", function () { | ||
return new Promise(function (resolve) { | ||
var v = 0; | ||
sync.update(function () { return v++; }, true); | ||
sync.render(function () { return v === 2 && resolve(); }, true); | ||
it("correctly keeps alive", () => { | ||
return new Promise((resolve) => { | ||
let v = 0; | ||
sync.update(() => v++, true); | ||
sync.render(() => v === 2 && resolve(), true); | ||
}); | ||
}); | ||
it("correctly cancels a keepAlive process", function () { | ||
return new Promise(function (resolve, reject) { | ||
var updateCount = 0; | ||
var renderCount = 0; | ||
var update = sync.update(function () { | ||
it("correctly cancels a keepAlive process", () => { | ||
return new Promise((resolve, reject) => { | ||
let updateCount = 0; | ||
let renderCount = 0; | ||
const update = sync.update(() => { | ||
updateCount++; | ||
@@ -104,3 +96,3 @@ if (updateCount === 4) | ||
}, true); | ||
sync.render(function () { | ||
sync.render(() => { | ||
renderCount++; | ||
@@ -107,0 +99,0 @@ if (renderCount === 6) { |
export function createRenderStep(runNextFrame) { | ||
var toRun = []; | ||
var toRunNextFrame = []; | ||
var numToRun = 0; | ||
var isProcessing = false; | ||
var toKeepAlive = new WeakSet(); | ||
var step = { | ||
schedule: function (callback, keepAlive, immediate) { | ||
if (keepAlive === void 0) { keepAlive = false; } | ||
if (immediate === void 0) { immediate = false; } | ||
var addToCurrentFrame = immediate && isProcessing; | ||
var buffer = addToCurrentFrame ? toRun : toRunNextFrame; | ||
let toRun = []; | ||
let toRunNextFrame = []; | ||
let numToRun = 0; | ||
let isProcessing = false; | ||
const toKeepAlive = new WeakSet(); | ||
const step = { | ||
schedule: (callback, keepAlive = false, immediate = false) => { | ||
const addToCurrentFrame = immediate && isProcessing; | ||
const buffer = addToCurrentFrame ? toRun : toRunNextFrame; | ||
if (keepAlive) | ||
@@ -22,4 +20,4 @@ toKeepAlive.add(callback); | ||
}, | ||
cancel: function (callback) { | ||
var index = toRunNextFrame.indexOf(callback); | ||
cancel: (callback) => { | ||
const index = toRunNextFrame.indexOf(callback); | ||
if (index !== -1) | ||
@@ -29,11 +27,10 @@ toRunNextFrame.splice(index, 1); | ||
}, | ||
process: function (frameData) { | ||
var _a; | ||
process: (frameData) => { | ||
isProcessing = true; | ||
_a = [toRunNextFrame, toRun], toRun = _a[0], toRunNextFrame = _a[1]; | ||
[toRun, toRunNextFrame] = [toRunNextFrame, toRun]; | ||
toRunNextFrame.length = 0; | ||
numToRun = toRun.length; | ||
if (numToRun) { | ||
for (var i = 0; i < numToRun; i++) { | ||
var callback = toRun[i]; | ||
for (let i = 0; i < numToRun; i++) { | ||
const callback = toRun[i]; | ||
callback(frameData); | ||
@@ -40,0 +37,0 @@ if (toKeepAlive.has(callback)) { |
import { onNextFrame, defaultTimestep } from "./on-next-frame"; | ||
import { createRenderStep } from "./create-render-step"; | ||
var maxElapsed = 40; | ||
var useDefaultElapsed = true; | ||
var runNextFrame = false; | ||
var isProcessing = false; | ||
var frame = { | ||
const maxElapsed = 40; | ||
let useDefaultElapsed = true; | ||
let runNextFrame = false; | ||
let isProcessing = false; | ||
const frame = { | ||
delta: 0, | ||
timestamp: 0, | ||
}; | ||
var stepsOrder = [ | ||
const stepsOrder = [ | ||
"read", | ||
@@ -18,11 +18,9 @@ "update", | ||
]; | ||
var steps = stepsOrder.reduce(function (acc, key) { | ||
acc[key] = createRenderStep(function () { return (runNextFrame = true); }); | ||
const steps = stepsOrder.reduce((acc, key) => { | ||
acc[key] = createRenderStep(() => (runNextFrame = true)); | ||
return acc; | ||
}, {}); | ||
var sync = stepsOrder.reduce(function (acc, key) { | ||
var step = steps[key]; | ||
acc[key] = function (process, keepAlive, immediate) { | ||
if (keepAlive === void 0) { keepAlive = false; } | ||
if (immediate === void 0) { immediate = false; } | ||
const sync = stepsOrder.reduce((acc, key) => { | ||
const step = steps[key]; | ||
acc[key] = (process, keepAlive = false, immediate = false) => { | ||
if (!runNextFrame) | ||
@@ -34,12 +32,12 @@ startLoop(); | ||
}, {}); | ||
var cancelSync = stepsOrder.reduce(function (acc, key) { | ||
const cancelSync = stepsOrder.reduce((acc, key) => { | ||
acc[key] = steps[key].cancel; | ||
return acc; | ||
}, {}); | ||
var flushSync = stepsOrder.reduce(function (acc, key) { | ||
acc[key] = function () { return steps[key].process(frame); }; | ||
const flushSync = stepsOrder.reduce((acc, key) => { | ||
acc[key] = () => steps[key].process(frame); | ||
return acc; | ||
}, {}); | ||
var processStep = function (stepId) { return steps[stepId].process(frame); }; | ||
var processFrame = function (timestamp) { | ||
const processStep = (stepId) => steps[stepId].process(frame); | ||
const processFrame = (timestamp) => { | ||
runNextFrame = false; | ||
@@ -58,3 +56,3 @@ frame.delta = useDefaultElapsed | ||
}; | ||
var startLoop = function () { | ||
const startLoop = () => { | ||
runNextFrame = true; | ||
@@ -65,5 +63,5 @@ useDefaultElapsed = true; | ||
}; | ||
var getFrameData = function () { return frame; }; | ||
const getFrameData = () => frame; | ||
export default sync; | ||
export { cancelSync, flushSync, getFrameData }; | ||
//# sourceMappingURL=index.js.map |
@@ -1,12 +0,8 @@ | ||
export var defaultTimestep = (1 / 60) * 1000; | ||
var getCurrentTime = typeof performance !== "undefined" | ||
? function () { return performance.now(); } | ||
: function () { return Date.now(); }; | ||
export var onNextFrame = typeof window !== "undefined" | ||
? function (callback) { | ||
return window.requestAnimationFrame(callback); | ||
} | ||
: function (callback) { | ||
return setTimeout(function () { return callback(getCurrentTime()); }, defaultTimestep); | ||
}; | ||
export const defaultTimestep = (1 / 60) * 1000; | ||
const getCurrentTime = typeof performance !== "undefined" | ||
? () => performance.now() | ||
: () => Date.now(); | ||
export const onNextFrame = typeof window !== "undefined" | ||
? (callback) => window.requestAnimationFrame(callback) | ||
: (callback) => setTimeout(() => callback(getCurrentTime()), defaultTimestep); | ||
//# sourceMappingURL=on-next-frame.js.map |
{ | ||
"name": "framesync", | ||
"license": "MIT", | ||
"version": "5.3.0", | ||
"version": "6.0.0-rc.1", | ||
"description": "A frame-synced render loop for JavaScript", | ||
@@ -10,16 +10,18 @@ "author": "Matt Perry", | ||
"types": "lib/index.d.ts", | ||
"module": "dist/es/index.js", | ||
"jsnext:main": "dist/es/index.js", | ||
"module": "dist/es/index.mjs", | ||
"jsnext:main": "dist/es/index.mjs", | ||
"unpkg": "./dist/framesync.min.js", | ||
"exports": { | ||
"import": "./dist/es/index.js", | ||
"require": "./dist/framesync.cjs.js", | ||
"default": "./dist/es/index.js" | ||
".": { | ||
"import": "./dist/es/index.mjs", | ||
"require": "./dist/framesync.cjs.js", | ||
"default": "./dist/framesync.cjs.js" | ||
}, | ||
"./package.json": "./package.json" | ||
}, | ||
"scripts": { | ||
"build": "tsc -p . && rollup -c && yarn measure", | ||
"postbuild": "babel $npm_package_module --out-file $npm_package_module --no-babelrc --plugins annotate-pure-calls", | ||
"watch": "rollup -c -w", | ||
"lint": "tslint -c tslint.json 'src/**/*.{ts}'", | ||
"test": "jest --maxWorkers=2", | ||
"test": "jest", | ||
"measure": "gzip -c dist/framesync.min.js | wc -c", | ||
@@ -43,7 +45,2 @@ "prepublishOnly": "npm run test && npm run build" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "^6.26.0", | ||
"babel-core": "^6.26.3", | ||
"babel-plugin-annotate-pure-calls": "^0.2.2" | ||
}, | ||
"jest": { | ||
@@ -50,0 +47,0 @@ "moduleFileExtensions": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
0
27
748
41422
1