time-queues 1.0.5 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -294
- package/package.json +11 -4
- package/src/FrameQueue.d.ts +71 -0
- package/src/FrameQueue.js +2 -0
- package/src/IdleQueue.d.ts +83 -0
- package/src/IdleQueue.js +2 -0
- package/src/ListQueue.d.ts +77 -0
- package/src/ListQueue.js +2 -0
- package/src/MicroTask.d.ts +17 -0
- package/src/MicroTask.js +2 -0
- package/src/MicroTaskQueue.d.ts +63 -0
- package/src/MicroTaskQueue.js +2 -0
- package/src/PageWatcher.d.ts +82 -0
- package/src/PageWatcher.js +2 -0
- package/src/Retainer.d.ts +47 -0
- package/src/Retainer.js +48 -0
- package/src/Scheduler.d.ts +94 -0
- package/src/Scheduler.js +11 -3
- package/src/Throttler.d.ts +79 -0
- package/src/Throttler.js +71 -0
- package/src/audit.d.ts +15 -0
- package/src/audit.js +20 -0
- package/src/debounce.d.ts +14 -0
- package/src/debounce.js +16 -0
- package/src/defer.d.ts +13 -0
- package/src/defer.js +2 -0
- package/src/sample.d.ts +17 -0
- package/src/sample.js +25 -0
- package/src/sleep.d.ts +9 -0
- package/src/sleep.js +13 -0
- package/src/throttle.d.ts +15 -0
- package/src/throttle.js +14 -0
- package/src/when-dom-loaded.d.ts +17 -0
- package/src/when-dom-loaded.js +3 -1
- package/src/when-loaded.d.ts +17 -0
- package/src/when-loaded.js +3 -1
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Throttles a function by ensuring it is not called more often than the specified interval.
|
|
3
|
+
* The first call calls the function and starts a timeout. Until the timeout expires, any subsequent calls are ignored.
|
|
4
|
+
* This function is similar to `audit()`, but the first seen arguments are passed to the function.
|
|
5
|
+
*
|
|
6
|
+
* @param fn The function to throttle.
|
|
7
|
+
* @param ms The minimum time interval between function calls, in milliseconds.
|
|
8
|
+
* @returns A throttled version of the function.
|
|
9
|
+
*/
|
|
10
|
+
export declare function throttle(
|
|
11
|
+
fn: (...args: unknown[]) => void,
|
|
12
|
+
ms: number
|
|
13
|
+
): (...args: unknown[]) => void;
|
|
14
|
+
|
|
15
|
+
export default throttle;
|
package/src/throttle.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// @ts-self-types="./throttle.d.ts"
|
|
2
|
+
|
|
3
|
+
'use strict';
|
|
4
|
+
|
|
5
|
+
export const throttle = (fn, ms) => {
|
|
6
|
+
let handle = null;
|
|
7
|
+
return (...args) => {
|
|
8
|
+
if (handle) return;
|
|
9
|
+
handle = setTimeout(() => (handle = null), ms);
|
|
10
|
+
fn(...args);
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export default throttle;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adds a function to the list of functions to be called when the DOM is loaded.
|
|
3
|
+
* If the DOM is already loaded, the function is called immediately.
|
|
4
|
+
*
|
|
5
|
+
* @param fn The function to add.
|
|
6
|
+
*/
|
|
7
|
+
export declare function whenDomLoaded(fn: () => void): void;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Removes a function from the list of functions to be called when the DOM is loaded.
|
|
11
|
+
*
|
|
12
|
+
* @param fn The function to remove.
|
|
13
|
+
* @returns `true` if the function was removed, `false` otherwise.
|
|
14
|
+
*/
|
|
15
|
+
export declare function remove(fn: () => void): boolean;
|
|
16
|
+
|
|
17
|
+
export default whenDomLoaded;
|
package/src/when-dom-loaded.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// @ts-self-types="./when-dom-loaded.d.ts"
|
|
2
|
+
|
|
1
3
|
'use strict';
|
|
2
4
|
|
|
3
5
|
import ValueList from 'list-toolkit/value-list.js';
|
|
@@ -12,7 +14,7 @@ export const remove = fn => {
|
|
|
12
14
|
}
|
|
13
15
|
}
|
|
14
16
|
return false;
|
|
15
|
-
}
|
|
17
|
+
};
|
|
16
18
|
|
|
17
19
|
const handleDomLoaded = () => {
|
|
18
20
|
while (!waitingForDom.isEmpty) waitingForDom.pop()();
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adds a function to the list of functions to be called when the document is loaded.
|
|
3
|
+
* If the document is already loaded, the function is called immediately.
|
|
4
|
+
*
|
|
5
|
+
* @param fn The function to add.
|
|
6
|
+
*/
|
|
7
|
+
export declare function whenLoaded(fn: () => void): void;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Removes a function from the list of functions to be called when the document is loaded.
|
|
11
|
+
*
|
|
12
|
+
* @param fn The function to remove.
|
|
13
|
+
* @returns `true` if the function was removed, `false` otherwise.
|
|
14
|
+
*/
|
|
15
|
+
export declare function remove(fn: () => void): boolean;
|
|
16
|
+
|
|
17
|
+
export default whenLoaded;
|
package/src/when-loaded.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// @ts-self-types="./when-loaded.d.ts"
|
|
2
|
+
|
|
1
3
|
'use strict';
|
|
2
4
|
|
|
3
5
|
import ValueList from 'list-toolkit/value-list.js';
|
|
@@ -12,7 +14,7 @@ export const remove = fn => {
|
|
|
12
14
|
}
|
|
13
15
|
}
|
|
14
16
|
return false;
|
|
15
|
-
}
|
|
17
|
+
};
|
|
16
18
|
|
|
17
19
|
const handleLoaded = () => {
|
|
18
20
|
while (!waitingForLoad.isEmpty) waitingForLoad.pop()();
|