From 3e671e5a23a6e516eab4d634e8ff58dc0465de44 Mon Sep 17 00:00:00 2001 From: Philip Walton Date: Wed, 19 Sep 2018 21:16:33 -0700 Subject: [PATCH] Update JSDoc comments to closure compiler syntax --- IdleQueue.mjs | 34 +++++++++++++++------------------- IdleValue.mjs | 2 +- defineIdleProperties.mjs | 4 ++-- defineIdleProperty.mjs | 4 ++-- idle-callback-polyfills.mjs | 6 +++--- lib/queueMicrotask.mjs | 6 ++++++ 6 files changed, 29 insertions(+), 27 deletions(-) diff --git a/IdleQueue.mjs b/IdleQueue.mjs index 8cb0d09..1f04945 100644 --- a/IdleQueue.mjs +++ b/IdleQueue.mjs @@ -33,9 +33,10 @@ export class IdleQueue { /** * Creates the IdleQueue instance and adds lifecycle event listeners to * run the queue if the page is hidden (with fallback behavior for Safari). - * @param {Object} [options] - * @param {boolean} [options.ensureTasksRun=false] - * @param {number} [options.defaultMinTaskTime=0] + * @param {{ + * ensureTasksRun: boolean, + * defaultMinTaskTime: number, + * }=} param1 */ constructor({ ensureTasksRun = false, @@ -70,21 +71,17 @@ export class IdleQueue { } /** - * @param {Function} task - * @param {Object} [options] - * @param {number} [options.minTaskTime] + * @param {...*} args */ pushTask(...args) { - this.addTask_('push', ...args); + this.addTask_(Array.prototype.push, ...args); } /** - * @param {Function} task - * @param {Object} [options] - * @param {number} [options.minTaskTime] + * @param {...*} args */ unshiftTask(...args) { - this.addTask_('unshift', ...args); + this.addTask_(Array.prototype.unshift, ...args); } /** @@ -115,7 +112,7 @@ export class IdleQueue { /** * Returns the state object for the currently running task. If no task is * running, null is returned. - * @return {Object} + * @return {?Object} */ getState() { return this.state_; @@ -147,19 +144,18 @@ export class IdleQueue { } /** - * @param {string} method Either 'push' or 'shift'. - * @param {Function} task - * @param {Object} [options] - * @param {number} [options.minTaskTime] + * @param {!Function} arrayMethod Either the Array.prototype{push|shift}. + * @param {!Function} task + * @param {{minTaskTime: number}=} param1 * @private */ - addTask_(method, task, {minTaskTime = this.defaultMinTaskTime_} = {}) { + addTask_(arrayMethod, task, {minTaskTime = this.defaultMinTaskTime_} = {}) { const state = { time: now(), visibilityState: document.visibilityState, }; - this.taskQueue_[method]({state, task, minTaskTime}); + arrayMethod.call(this.taskQueue_, {state, task, minTaskTime}); this.scheduleTasksToRun_(); } @@ -187,7 +183,7 @@ export class IdleQueue { * If an `IdleDeadline` object is passed (as is with `requestIdleCallback`) * then the tasks are run until there's no time remaining, at which point * we yield to input or other script and wait until the next idle time. - * @param {IdleDeadline} [deadline] + * @param {IdleDeadline=} deadline * @private */ runTasks_(deadline = undefined) { diff --git a/IdleValue.mjs b/IdleValue.mjs index 5ccc26e..1ba3568 100644 --- a/IdleValue.mjs +++ b/IdleValue.mjs @@ -23,7 +23,7 @@ import {cIC, rIC} from './idle-callback-polyfills.mjs'; export class IdleValue { /** * Accepts a function to initialize the value of a variable when idle. - * @param {Function} init + * @param {!Function} init */ constructor(init) { this.init_ = init; diff --git a/defineIdleProperties.mjs b/defineIdleProperties.mjs index 61cf313..927f318 100644 --- a/defineIdleProperties.mjs +++ b/defineIdleProperties.mjs @@ -18,8 +18,8 @@ import {defineIdleProperty} from './defineIdleProperty.mjs'; /** - * @param {Object} obj The object to define the property on. - * @param {Object} props A mapping of property names to + * @param {!Object} obj The object to define the property on. + * @param {!Object} props A mapping of property names to * initialization functions to be run idly. */ export const defineIdleProperties = (obj, props) => { diff --git a/defineIdleProperty.mjs b/defineIdleProperty.mjs index 4a76187..d6a63ba 100644 --- a/defineIdleProperty.mjs +++ b/defineIdleProperty.mjs @@ -18,9 +18,9 @@ import {IdleValue} from './IdleValue.mjs'; /** - * @param {Object} obj The object to define the property on. + * @param {!Object} obj The object to define the property on. * @param {string} prop The property name. - * @param {Function} init An initialization function to by run idly. + * @param {!Function} init An initialization function to by run idly. */ export const defineIdleProperty = (obj, prop, init) => { const idleValue = new IdleValue(init); diff --git a/idle-callback-polyfills.mjs b/idle-callback-polyfills.mjs index ff10085..49b3c08 100644 --- a/idle-callback-polyfills.mjs +++ b/idle-callback-polyfills.mjs @@ -42,7 +42,7 @@ class IdleDealine { * callback function and runs it at the next idle period, passing in an * object with a `timeRemaining()` method. * @private - * @param {Function} callback + * @param {!Function} callback * @return {number} */ const requestIdleCallbackShim = (callback) => { @@ -55,7 +55,7 @@ const requestIdleCallbackShim = (callback) => { * A minimal shim for the cancelIdleCallback function. This accepts a * handle identifying the idle callback to cancel. * @private - * @param {number} handle + * @param {number|null} handle */ const cancelIdleCallbackShim = (handle) => { clearTimeout(handle); @@ -65,7 +65,7 @@ const cancelIdleCallbackShim = (handle) => { /** * The native `requestIdleCallback()` function or `cancelIdleCallbackShim()` *.if the browser doesn't support it. - * @param {Function} callback + * @param {!Function} callback * @return {number} */ export const rIC = supportsRequestIdleCallback_ ? diff --git a/lib/queueMicrotask.mjs b/lib/queueMicrotask.mjs index f3d9b58..84c4203 100644 --- a/lib/queueMicrotask.mjs +++ b/lib/queueMicrotask.mjs @@ -14,12 +14,18 @@ * limitations under the License. */ +/** + * @return {!Function} + */ const createQueueMicrotaskViaPromises = () => { return (microtask) => { Promise.resolve().then(microtask); }; }; +/** + * @return {!Function} + */ const createQueueMicrotaskViaMutationObserver = () => { let i = 0; let microtaskQueue = [];