frame-scheduling
Advanced tools
Comparing version 0.4.1 to 0.5.0
{ | ||
"name": "frame-scheduling", | ||
"version": "0.4.1", | ||
"version": "0.5.0", | ||
"description": "Asynchronous start of functions in JS. Supports priority and interrupt execution every 16 milliseconds, to achieve 60fps.", | ||
@@ -5,0 +5,0 @@ "main": "lib/frameScheduling.js", |
const context = typeof window !== "undefined" ? window : global; | ||
let defer: Function; | ||
let defer: (f: () => void) => void; | ||
if ("requestAnimationFrame" in context) { | ||
defer = requestAnimationFrame.bind(context); | ||
} else if ("setImmediate" in context) { | ||
defer = setImmediate.bind(context); | ||
} else { | ||
@@ -18,5 +20,5 @@ defer = setTimeout.bind(context); | ||
interface listNode { | ||
value: Function; | ||
next: listNode | null; | ||
interface IListNode { | ||
value: () => void; | ||
next: IListNode | null; | ||
} | ||
@@ -26,4 +28,4 @@ | ||
private length: number; | ||
private head: listNode | null; | ||
private last: listNode; | ||
private head: IListNode | null; | ||
private last: IListNode; | ||
@@ -35,6 +37,6 @@ constructor() { | ||
push(value: Function) { | ||
const node: listNode = { | ||
value: value, | ||
next: null | ||
public push(value: () => void) { | ||
const node: IListNode = { | ||
next: null, | ||
value, | ||
}; | ||
@@ -53,4 +55,4 @@ | ||
shift() { | ||
const currentHead = <listNode>this.head; | ||
public shift() { | ||
const currentHead = this.head as IListNode; | ||
const value = currentHead.value; | ||
@@ -64,3 +66,3 @@ | ||
isEmpty() { | ||
public isEmpty() { | ||
return this.length === 0; | ||
@@ -77,6 +79,6 @@ } | ||
const sortJobsByNumber = (jobs: Object) => { | ||
const sortJobsByNumber = (jobs: object) => { | ||
if (!jobsSortActual) { | ||
jobsSortCached = Object.keys(jobs).sort( | ||
(left: string, right: string) => Number(left) - Number(right) | ||
(left: string, right: string) => Number(left) - Number(right), | ||
); | ||
@@ -97,3 +99,3 @@ jobsSortActual = true; | ||
const addJob = (callback: Function, priority: number) => { | ||
const addJob = (callback: () => void, priority: number) => { | ||
if (!listJobs[priority]) { | ||
@@ -109,3 +111,3 @@ listJobs[priority] = new LinkedList(); | ||
for (var i = keys.length; i > 0; i--) { | ||
for (let i = keys.length; i > 0; i--) { | ||
const key = keys[i - 1]; | ||
@@ -139,3 +141,3 @@ | ||
} catch (e) { | ||
console.error(e); | ||
console.error(e); // tslint:disable-line | ||
} | ||
@@ -160,3 +162,3 @@ | ||
return function scheduling(callback: Function, { priority = P_NORMAL } = {}) { | ||
return function scheduling(callback: () => void, { priority = P_NORMAL } = {}) { | ||
addJob(callback, priority); | ||
@@ -163,0 +165,0 @@ |
@@ -19,3 +19,3 @@ { | ||
}, | ||
"include": ["src/**/*", "test/**/*"] | ||
"include": ["src/**/*", "tests/**/*"] | ||
} |
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
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
16163
11
415