Skip to content

Commit

Permalink
Update JSDoc comments to closure compiler syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
philipwalton committed Sep 20, 2018
1 parent a8fa882 commit 3e671e5
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 27 deletions.
34 changes: 15 additions & 19 deletions IdleQueue.mjs
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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_;
Expand Down Expand Up @@ -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_();
}
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion IdleValue.mjs
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions defineIdleProperties.mjs
Expand Up @@ -18,8 +18,8 @@ import {defineIdleProperty} from './defineIdleProperty.mjs';


/**
* @param {Object} obj The object to define the property on.
* @param {Object<string, Function>} props A mapping of property names to
* @param {!Object} obj The object to define the property on.
* @param {!Object<string, !Function>} props A mapping of property names to
* initialization functions to be run idly.
*/
export const defineIdleProperties = (obj, props) => {
Expand Down
4 changes: 2 additions & 2 deletions defineIdleProperty.mjs
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions idle-callback-polyfills.mjs
Expand Up @@ -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) => {
Expand All @@ -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);
Expand All @@ -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_ ?
Expand Down
6 changes: 6 additions & 0 deletions lib/queueMicrotask.mjs
Expand Up @@ -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 = [];
Expand Down

0 comments on commit 3e671e5

Please sign in to comment.