From 0442d1f899a67a5713b4f66962a170c34945a89b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Wed, 6 Mar 2019 11:57:36 +0100 Subject: [PATCH 1/2] Set-up auto-generated docs --- bin/update-readmes.js | 2 +- packages/priority-queue/README.md | 24 +++++++++++++++++++++--- packages/priority-queue/src/index.js | 22 ++++++++++++++++++++++ 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/bin/update-readmes.js b/bin/update-readmes.js index 038cfa34c62133..2f5e0ad400ca02 100755 --- a/bin/update-readmes.js +++ b/bin/update-readmes.js @@ -25,7 +25,7 @@ const packages = [ //'i18n', //'keycodes', //'plugins', - //'priority-queue', + 'priority-queue', //'redux-routine', //'rich-text', //'shortcode', diff --git a/packages/priority-queue/README.md b/packages/priority-queue/README.md index 2405c6fbd6c995..02661ee1f7061b 100644 --- a/packages/priority-queue/README.md +++ b/packages/priority-queue/README.md @@ -10,9 +10,20 @@ Install the module npm install @wordpress/priority-queue --save ``` -_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 + + + +### 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 import { createQueue } from '@wordpress/priority-queue'; @@ -21,7 +32,7 @@ const queue = createQueue(); // Context objects. const ctx1 = {}; -const ctx2 = {}; +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' ) ); @@ -29,4 +40,11 @@ queue.add( ctx2, () => console.log( 'This won\'t be printed' ) ); queue.add( ctx2, () => console.log( 'This will be printed second' ) ); ``` +**Returns** + +`Object`: Queue object with `add` and `flush` methods. + + + +

Code is Poetry.

diff --git a/packages/priority-queue/src/index.js b/packages/priority-queue/src/index.js index 5934fe74875ef3..50b1befba01a9d 100644 --- a/packages/priority-queue/src/index.js +++ b/packages/priority-queue/src/index.js @@ -1,5 +1,27 @@ 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 = () => { const waitingList = []; const elementsMap = new WeakMap(); From 3afb5b70d16b26c094c3e63a23696ef29a08cda9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Wed, 6 Mar 2019 12:03:30 +0100 Subject: [PATCH 2/2] Update docs --- packages/priority-queue/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/priority-queue/README.md b/packages/priority-queue/README.md index 02661ee1f7061b..d9f34770344362 100644 --- a/packages/priority-queue/README.md +++ b/packages/priority-queue/README.md @@ -10,7 +10,7 @@ Install the module npm install @wordpress/priority-queue --save ``` -*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)._ ## API