@wordpress/priority-queue
Advanced tools
Comparing version
@@ -8,4 +8,2 @@ /** | ||
* Enqueued callback to invoke once idle time permits. | ||
* | ||
* @typedef {()=>void} WPPriorityQueueCallback | ||
*/ | ||
@@ -15,36 +13,9 @@ | ||
* An object used to associate callbacks in a particular context grouping. | ||
* | ||
* @typedef {{}} WPPriorityQueueContext | ||
*/ | ||
/** | ||
* Function to add callback to priority queue. | ||
* | ||
* @typedef {(element:WPPriorityQueueContext,item:WPPriorityQueueCallback)=>void} WPPriorityQueueAdd | ||
* Interface for the priority queue instance. | ||
*/ | ||
/** | ||
* Function to flush callbacks from priority queue. | ||
* | ||
* @typedef {(element:WPPriorityQueueContext)=>boolean} WPPriorityQueueFlush | ||
*/ | ||
/** | ||
* Reset the queue. | ||
* | ||
* @typedef {()=>void} WPPriorityQueueReset | ||
*/ | ||
/** | ||
* Priority queue instance. | ||
* | ||
* @typedef {Object} WPPriorityQueue | ||
* | ||
* @property {WPPriorityQueueAdd} add Add callback to queue for context. | ||
* @property {WPPriorityQueueFlush} flush Flush queue for context. | ||
* @property {WPPriorityQueueFlush} cancel Clear queue for context. | ||
* @property {WPPriorityQueueReset} reset Reset queue. | ||
*/ | ||
/** | ||
* Creates a context-aware queue that only executes | ||
@@ -72,3 +43,2 @@ * the last task of a given context. | ||
export const createQueue = () => { | ||
/** @type {Map<WPPriorityQueueContext, WPPriorityQueueCallback>} */ | ||
const waitingList = new Map(); | ||
@@ -116,4 +86,2 @@ let isRunning = false; | ||
* | ||
* @type {WPPriorityQueueAdd} | ||
* | ||
* @param {WPPriorityQueueContext} element Context object. | ||
@@ -134,4 +102,2 @@ * @param {WPPriorityQueueCallback} item Callback function. | ||
* | ||
* @type {WPPriorityQueueFlush} | ||
* | ||
* @param {WPPriorityQueueContext} element Context object. | ||
@@ -156,4 +122,2 @@ * | ||
* | ||
* @type {WPPriorityQueueFlush} | ||
* | ||
* @param {WPPriorityQueueContext} element Context object. | ||
@@ -169,4 +133,2 @@ * | ||
* Reset the queue without running the pending callbacks. | ||
* | ||
* @type {WPPriorityQueueReset} | ||
*/ | ||
@@ -173,0 +135,0 @@ const reset = () => { |
@@ -7,7 +7,7 @@ /** | ||
/** | ||
* @typedef {( timeOrDeadline: IdleDeadline | number ) => void} Callback | ||
* Internal dependencies | ||
*/ | ||
/** | ||
* @return {(callback: Callback) => void} RequestIdleCallback | ||
* @return A function that schedules a callback when the browser is idle or via setTimeout on the server. | ||
*/ | ||
@@ -14,0 +14,0 @@ export function createRequestIdleCallback() { |
@@ -1,43 +0,55 @@ | ||
export function createQueue(): WPPriorityQueue; | ||
/** | ||
* Enqueued callback to invoke once idle time permits. | ||
*/ | ||
export type WPPriorityQueueCallback = () => void; | ||
export type WPPriorityQueueCallback = VoidFunction; | ||
/** | ||
* An object used to associate callbacks in a particular context grouping. | ||
*/ | ||
export type WPPriorityQueueContext = {}; | ||
export type WPPriorityQueueContext = object; | ||
/** | ||
* Function to add callback to priority queue. | ||
* Interface for the priority queue instance. | ||
*/ | ||
export type WPPriorityQueueAdd = (element: WPPriorityQueueContext, item: WPPriorityQueueCallback) => void; | ||
/** | ||
* Function to flush callbacks from priority queue. | ||
*/ | ||
export type WPPriorityQueueFlush = (element: WPPriorityQueueContext) => boolean; | ||
/** | ||
* Reset the queue. | ||
*/ | ||
export type WPPriorityQueueReset = () => void; | ||
/** | ||
* Priority queue instance. | ||
*/ | ||
export type WPPriorityQueue = { | ||
export interface WPPriorityQueue { | ||
/** | ||
* Add callback to queue for context. | ||
* Add a callback to the queue for a given context. | ||
*/ | ||
add: WPPriorityQueueAdd; | ||
add: (element: WPPriorityQueueContext, item: WPPriorityQueueCallback) => void; | ||
/** | ||
* Flush queue for context. | ||
* Flush and run the callback for a given context immediately. | ||
* @return true if a callback was run, false otherwise. | ||
*/ | ||
flush: WPPriorityQueueFlush; | ||
flush: (element: WPPriorityQueueContext) => boolean; | ||
/** | ||
* Clear queue for context. | ||
* Cancel (remove) the callback for a given context without running it. | ||
* @return true if a callback was cancelled, false otherwise. | ||
*/ | ||
cancel: WPPriorityQueueFlush; | ||
cancel: (element: WPPriorityQueueContext) => boolean; | ||
/** | ||
* Reset queue. | ||
* Reset the entire queue, clearing pending callbacks. | ||
*/ | ||
reset: WPPriorityQueueReset; | ||
}; | ||
reset: VoidFunction; | ||
} | ||
/** | ||
* Creates a context-aware queue that only executes | ||
* the last task of a given context. | ||
* | ||
* @example | ||
*```js | ||
* import { createQueue } from '@wordpress/priority-queue'; | ||
* | ||
* const queue = createQueue(); | ||
* | ||
* // Context objects. | ||
* const ctx1 = {}; | ||
* const ctx2 = {}; | ||
* | ||
* // For a given context in the queue, only the last callback is executed. | ||
* queue.add( ctx1, () => console.log( 'This will be printed first' ) ); | ||
* queue.add( ctx2, () => console.log( 'This won\'t be printed' ) ); | ||
* queue.add( ctx2, () => console.log( 'This will be printed second' ) ); | ||
*``` | ||
* | ||
* @return {WPPriorityQueue} Queue object with `add`, `flush` and `reset` methods. | ||
*/ | ||
export declare const createQueue: () => WPPriorityQueue; | ||
//# sourceMappingURL=index.d.ts.map |
/** | ||
* @typedef {( timeOrDeadline: IdleDeadline | number ) => void} Callback | ||
* External dependencies | ||
*/ | ||
import 'requestidlecallback'; | ||
/** | ||
* @return {(callback: Callback) => void} RequestIdleCallback | ||
* Internal dependencies | ||
*/ | ||
export function createRequestIdleCallback(): (callback: Callback) => void; | ||
declare const _default: (callback: Callback) => void; | ||
import type { RequestIdleCallbackCallback } from './types'; | ||
/** | ||
* @return A function that schedules a callback when the browser is idle or via setTimeout on the server. | ||
*/ | ||
export declare function createRequestIdleCallback(): ((callback: RequestIdleCallbackCallback) => void) | ({ | ||
(callback: IdleRequestCallback, options?: IdleRequestOptions): number; | ||
(callback: (deadline: IdleDeadline) => void, options?: IdleRequestOptions): IdleCallbackHandle; | ||
} & typeof requestIdleCallback); | ||
declare const _default: ((callback: RequestIdleCallbackCallback) => void) | ({ | ||
(callback: IdleRequestCallback, options?: IdleRequestOptions): number; | ||
(callback: (deadline: IdleDeadline) => void, options?: IdleRequestOptions): IdleCallbackHandle; | ||
} & typeof requestIdleCallback); | ||
export default _default; | ||
export type Callback = (timeOrDeadline: IdleDeadline | number) => void; | ||
//# sourceMappingURL=request-idle-callback.d.ts.map |
@@ -15,4 +15,2 @@ "use strict"; | ||
* Enqueued callback to invoke once idle time permits. | ||
* | ||
* @typedef {()=>void} WPPriorityQueueCallback | ||
*/ | ||
@@ -22,36 +20,9 @@ | ||
* An object used to associate callbacks in a particular context grouping. | ||
* | ||
* @typedef {{}} WPPriorityQueueContext | ||
*/ | ||
/** | ||
* Function to add callback to priority queue. | ||
* | ||
* @typedef {(element:WPPriorityQueueContext,item:WPPriorityQueueCallback)=>void} WPPriorityQueueAdd | ||
* Interface for the priority queue instance. | ||
*/ | ||
/** | ||
* Function to flush callbacks from priority queue. | ||
* | ||
* @typedef {(element:WPPriorityQueueContext)=>boolean} WPPriorityQueueFlush | ||
*/ | ||
/** | ||
* Reset the queue. | ||
* | ||
* @typedef {()=>void} WPPriorityQueueReset | ||
*/ | ||
/** | ||
* Priority queue instance. | ||
* | ||
* @typedef {Object} WPPriorityQueue | ||
* | ||
* @property {WPPriorityQueueAdd} add Add callback to queue for context. | ||
* @property {WPPriorityQueueFlush} flush Flush queue for context. | ||
* @property {WPPriorityQueueFlush} cancel Clear queue for context. | ||
* @property {WPPriorityQueueReset} reset Reset queue. | ||
*/ | ||
/** | ||
* Creates a context-aware queue that only executes | ||
@@ -79,3 +50,2 @@ * the last task of a given context. | ||
const createQueue = () => { | ||
/** @type {Map<WPPriorityQueueContext, WPPriorityQueueCallback>} */ | ||
const waitingList = new Map(); | ||
@@ -123,4 +93,2 @@ let isRunning = false; | ||
* | ||
* @type {WPPriorityQueueAdd} | ||
* | ||
* @param {WPPriorityQueueContext} element Context object. | ||
@@ -141,4 +109,2 @@ * @param {WPPriorityQueueCallback} item Callback function. | ||
* | ||
* @type {WPPriorityQueueFlush} | ||
* | ||
* @param {WPPriorityQueueContext} element Context object. | ||
@@ -163,4 +129,2 @@ * | ||
* | ||
* @type {WPPriorityQueueFlush} | ||
* | ||
* @param {WPPriorityQueueContext} element Context object. | ||
@@ -176,4 +140,2 @@ * | ||
* Reset the queue without running the pending callbacks. | ||
* | ||
* @type {WPPriorityQueueReset} | ||
*/ | ||
@@ -180,0 +142,0 @@ const reset = () => { |
@@ -14,7 +14,7 @@ "use strict"; | ||
/** | ||
* @typedef {( timeOrDeadline: IdleDeadline | number ) => void} Callback | ||
* Internal dependencies | ||
*/ | ||
/** | ||
* @return {(callback: Callback) => void} RequestIdleCallback | ||
* @return A function that schedules a callback when the browser is idle or via setTimeout on the server. | ||
*/ | ||
@@ -21,0 +21,0 @@ function createRequestIdleCallback() { |
{ | ||
"name": "@wordpress/priority-queue", | ||
"version": "3.27.0", | ||
"version": "3.27.1-next.46f643fa0.0", | ||
"description": "Generic browser priority queue.", | ||
@@ -39,3 +39,3 @@ "author": "The WordPress Contributors", | ||
}, | ||
"gitHead": "abe06a6f2aef8d03c30ea9d5b3e133f041e523b1" | ||
"gitHead": "17e600e091675c5e3d809adfea23ac456bbeae19" | ||
} |
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
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
101448
1.52%28
33.33%726
-3.59%1
Infinity%1
Infinity%