@wordpress/priority-queue
Advanced tools
Comparing version 1.0.0 to 1.1.0
var requestIdleCallback = window.requestIdleCallback ? window.requestIdleCallback : window.requestAnimationFrame; | ||
/** | ||
* 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 {Object} Queue object with `add` and `flush` methods. | ||
*/ | ||
export var createQueue = function createQueue() { | ||
@@ -3,0 +26,0 @@ var waitingList = []; |
@@ -8,2 +8,24 @@ "use strict"; | ||
var requestIdleCallback = window.requestIdleCallback ? window.requestIdleCallback : window.requestAnimationFrame; | ||
/** | ||
* 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 {Object} Queue object with `add` and `flush` methods. | ||
*/ | ||
@@ -10,0 +32,0 @@ var createQueue = function createQueue() { |
@@ -1,3 +0,3 @@ | ||
### 1.0.0 (Unreleased) | ||
### 1.0.0 (2019-03-06) | ||
Initial release. |
{ | ||
"name": "@wordpress/priority-queue", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Generic browser priority queue.", | ||
@@ -30,3 +30,3 @@ "author": "The WordPress Contributors", | ||
}, | ||
"gitHead": "80d228669adadb8dfcd24b8421517fed3be2d474" | ||
"gitHead": "1e024a20a20369af7bc9720a676fdd3837a3a105" | ||
} |
@@ -13,6 +13,17 @@ # Priority Queue | ||
_This package assumes that your code will run in an **ES2015+** environment. If you're using an environment that has limited or no support for ES2015+ such as lower versions of IE then using [core-js](https://github.com/zloirock/core-js) or [@babel/polyfill](https://babeljs.io/docs/en/next/babel-polyfill) will add support for these methods. Learn more about it in [Babel docs](https://babeljs.io/docs/en/next/caveats). | ||
_This package assumes that your code will run in an **ES2015+** environment. If you're using an environment that has limited or no support for ES2015+ such as lower versions of IE then using [core-js](https://github.com/zloirock/core-js) or [@babel/polyfill](https://babeljs.io/docs/en/next/babel-polyfill) will add support for these methods. Learn more about it in [Babel docs](https://babeljs.io/docs/en/next/caveats)._ | ||
## Usage | ||
## API | ||
<!-- START TOKEN(Autogenerated API docs) --> | ||
### createQueue | ||
[src/index.js#L25-L72](src/index.js#L25-L72) | ||
Creates a context-aware queue that only executes | ||
the last task of a given context. | ||
**Usage** | ||
```js | ||
@@ -25,3 +36,3 @@ import { createQueue } from '@wordpress/priority-queue'; | ||
const ctx1 = {}; | ||
const ctx2 = {}; | ||
const ctx2 = {}; | ||
@@ -34,2 +45,9 @@ // For a given context in the queue, only the last callback is executed. | ||
**Returns** | ||
`Object`: Queue object with `add` and `flush` methods. | ||
<!-- END TOKEN(Autogenerated API docs) --> | ||
<br/><br/><p align="center"><img src="https://s.w.org/style/images/codeispoetry.png?1" alt="Code is Poetry." /></p> |
const requestIdleCallback = window.requestIdleCallback ? window.requestIdleCallback : window.requestAnimationFrame; | ||
/** | ||
* 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 {Object} Queue object with `add` and `flush` methods. | ||
*/ | ||
export const createQueue = () => { | ||
@@ -4,0 +26,0 @@ const waitingList = []; |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
34559
195
51
1