feat(nanoscheduler): new type definition (#45878)

- definition file
- tests

https://www.npmjs.com/package/nanoscheduler
https://github.com/choojs/nanoscheduler#readme

Thanks!
This commit is contained in:
Piotr Błażejewicz (Peter Blazejewicz) 2020-07-06 21:43:08 +02:00 committed by GitHub
parent 7a7ad43ca1
commit a5433cbce9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 66 additions and 0 deletions

27
types/nanoscheduler/index.d.ts vendored Normal file
View File

@ -0,0 +1,27 @@
// Type definitions for nanoscheduler 1.0
// Project: https://github.com/choojs/nanoscheduler#readme
// Definitions by: Piotr Błażejewicz <https://github.com/peterblazejewicz>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/**
* Create a new scheduler instance.
* The instance is shared as a singleton on window (if available).
*/
declare function createScheduler(): scheduler.NanoScheduler;
declare namespace scheduler {
/**
* Schedule work to be completed when the user agent is idle. Weighs 270 bytes compressed.
*/
abstract class NanoScheduler {
constructor(hasWindow: boolean);
/**
* Push a callback into the scheduler, to be executed when the user agent is idle.
*/
push(cb: () => void): void;
schedule(): void;
setTimeout(cb: () => void): void;
}
}
export = createScheduler;

View File

@ -0,0 +1,15 @@
/// <reference lib="DOM" />
import NanoScheduler = require('nanoscheduler');
const scheduler = NanoScheduler(); // $ExpectTYpe NanoScheduler
scheduler.push(() => {
// callback
});
scheduler.schedule();
scheduler.setTimeout(() => {
// done
});
// usage sample
let i = 10000;
while (i--) scheduler.push(() => console.log(`idle time! ${Date.now()}`));

View File

@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"nanoscheduler-tests.ts"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }