Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jsdocs #63

Merged
merged 4 commits into from
Nov 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ruby-2.2.0
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source "http://rubygems.org"

gem 'jekyll', '>=3.1.6'
gem 'kramdown'
gem 'jekyll-github-metadata'
6 changes: 6 additions & 0 deletions docs/_config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
source: .
layouts_dir: ./themes/jekyll/_layouts/
includes_dir: ./themes/jekyll/_includes/

# This adds github pages data
gems: ['jekyll-github-metadata']
4 changes: 4 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
layout: index
navigation_weight: 0
---
19 changes: 19 additions & 0 deletions jsdoc.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"source": {
"include": [
"./projects"
],
"excludePattern": "((^|\\/|\\\\)build(\\/|\\\\)|(^|\\/|\\\\)test(\\/|\\\\))"
},
"plugins": [
"node_modules/jsdoc-strip-async-await",
"plugins/markdown"
],
"opts": {
"template": "node_modules/npm-publish-scripts/build/themes/jsdoc",
"recurse": true
},
"markdown": {
"idInHeadings": true
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"gulp-mocha": "^3.0.1",
"gulp-rename": "^1.2.2",
"gulp-rollup": "^2.5.1",
"jsdoc-strip-async-await": "^0.1.0",
"minimist": "^1.2.0",
"mockdate": "^1.0.4",
"operadriver": "^0.2.2",
Expand All @@ -56,7 +57,7 @@
"rollup-plugin-commonjs": "^5.0.4",
"rollup-plugin-node-resolve": "^2.0.0",
"run-sequence": "^1.2.2",
"selenium-assistant": "^2.0.5",
"selenium-assistant": "^3.0.0",
"serve-index": "^1.8.0",
"serve-static": "^1.11.1",
"sw-testing-helpers": "0.1.4"
Expand Down
8 changes: 5 additions & 3 deletions projects/sw-broadcast-cache-update/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@
limitations under the License.
*/

/**
* sw-broadcast-cache-update Module
* @module sw-broadcast-cache-update
*/

import Behavior from './lib/behavior';
import broadcastUpdate from './lib/broadcast-update';
import {cacheUpdatedMessageType} from './lib/constants';
import sameResponses from './lib/responses-are-same';

/**
* @namespace goog.broadcastCacheUpdate
*/
export {
Behavior,
broadcastUpdate,
Expand Down
17 changes: 10 additions & 7 deletions projects/sw-broadcast-cache-update/src/lib/behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import responsesAreSame from './responses-are-same';
import {defaultHeadersToCheck, defaultSource} from './constants';

/**
* @memberof module:sw-broadcast-cache-update
*
* @example
* // Used as an automatically invoked as "behavior" by a RequestWrapper:
*
Expand Down Expand Up @@ -66,19 +68,20 @@ import {defaultHeadersToCheck, defaultSource} from './constants';
class Behavior {
/**
* Creates a new `Behavior` instance, which is used to compare two
* [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)s
* [Responses](https://developer.mozilla.org/en-US/docs/Web/API/Response)
* and use the {@link https://developers.google.com/web/updates/2016/09/broadcastchannel|Broadcast Channel API}
* to notify interested parties when those `Response`s differ.
* to notify interested parties when those Responses differ.
*
* For efficiency's sake, the underlying response bodies are not compared;
* only specific response headers are checked.
*
* @param {string} $0.channelName The name that will be used when creating the
* [`BroadcastChannel`](https://developer.mozilla.org/en-US/docs/Web/API/BroadcastChannel/BroadcastChannel).
* @param {Array.<string>} [$0.headersToCheck] A list of headers that will be
* @param {Object} input The input object to this function.
* @param {string} input.channelName The name that will be used when creating
* the [`BroadcastChannel`](https://developer.mozilla.org/en-US/docs/Web/API/BroadcastChannel/BroadcastChannel).
* @param {Array<string>} input.headersToCheck A list of headers that will be
* used to determine whether the `Response`s differ. If not provided,
* the values `['content-length', 'etag', 'last-modified']` are used.
* @param {string} [$0.source] An attribution value that will be used in the
* @param {string} input.source An attribution value that will be used in the
* broadcast message to indicate where the update originated. If not
* provided, a
* {@link constants#defaultSource|default value} will be used.
Expand Down Expand Up @@ -132,7 +135,7 @@ class Behavior {

/**
* An explicit method to call from your own code to trigger the comparison of
* two [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
* two [Response](https://developer.mozilla.org/en-US/docs/Web/API/Response)
* and fire off a notification via the
* {@link https://developers.google.com/web/updates/2016/09/broadcastchannel|Broadcast Channel API}
* if they differ.
Expand Down
14 changes: 9 additions & 5 deletions projects/sw-broadcast-cache-update/src/lib/broadcast-update.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,16 @@ import {cacheUpdatedMessageType} from './constants';
* }
* ```
*
* @param {BroadcastChannel} $0.channel The `BroadcastChannel` to use.
* @param {string} $0.cacheName The name of the cache in which the updated
* @memberof module:sw-broadcast-cache-update
* @type {function}
*
* @param {Object} input
* @param {BroadcastChannel} input.channel The `BroadcastChannel` to use.
* @param {string} input.cacheName The name of the cache in which the updated
* `Response` was stored.
* @param {string} $0.url The URL associated with the updated `Response`.
* @param {string} $0.source A string identifying this library as the source of
* the update message.
* @param {string} input.url The URL associated with the updated `Response`.
* @param {string} input.source A string identifying this library as the source
* of the update message.
*/
function broadcastUpdate({channel, cacheName, url, source}) {
assert.isInstance({channel}, BroadcastChannel);
Expand Down
19 changes: 12 additions & 7 deletions projects/sw-broadcast-cache-update/src/lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,20 @@
limitations under the License.
*/


/**
* @type {string} The value `'CACHE_UPDATED'`, used as the `type` field of the
* update message.
* The value `'CACHE_UPDATED'`, used as the `type` field of the update message.
*
* @memberof module:sw-broadcast-cache-update
* @type {string}
*/
const cacheUpdatedMessageType = 'CACHE_UPDATED';

/**
* The default headers to compare when determining whether two `Response`
* objects are different.
*
* @private
* @type {Array.<string>} The default headers to compare when determining
* whether two `Response` objects are different.
* @type {Array<string>}
*/
const defaultHeadersToCheck = [
'content-length',
Expand All @@ -32,9 +35,11 @@ const defaultHeadersToCheck = [
];

/**
* The value `'sw-broadcast-cache-update'`, used as the `meta` field of the
* update message.
*
* @private
* @type {string} The value `'sw-broadcast-cache-update'`, used as the `meta`
* field of the update message.
* @type {string}
*/
const defaultSource = 'sw-broadcast-cache-update';

Expand Down
10 changes: 7 additions & 3 deletions projects/sw-broadcast-cache-update/src/lib/responses-are-same.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ import assert from '../../../../lib/assert';
* Given two `Response`s, compares several header values to see if they are
* the same or not.
*
* @param {Response} $0.first One of the `Response`s.
* @param {Response} $0.second Another of the `Response`s.
* @param {Array.<string>} $0.headersToCheck A list of headers that will be
* @memberof module:sw-broadcast-cache-update
* @type {function}
*
* @param {Object} input
* @param {Response} input.first One of the `Response`s.
* @param {Response} input.second Another of the `Response`s.
* @param {Array<string>} input.headersToCheck A list of headers that will be
* used to determine whether the `Response`s differ.
* @return {boolean} Whether or not the `Response` objects are assumed to be
* the same.
Expand Down
5 changes: 5 additions & 0 deletions projects/sw-cache-expiration/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
limitations under the License.
*/

/**
* sw-cache-expiration Module
* @module sw-cache-expiration
*/

import Behavior from './lib/behavior';

export {Behavior};
75 changes: 70 additions & 5 deletions projects/sw-cache-expiration/src/lib/behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,53 @@ import Configuration from './configuration';
import assert from '../../../../lib/assert';
import {idbName, idbVersion} from './constants';

export default class Behavior {
constructor({configuration} = {}) {
/**
* TODO Behavior Description
* @memberof module:sw-cache-expiration
*/
class Behavior {
/**
* @param {Object} input
* @param {Object} input.configuration
*/
constructor({configuration}) {
if (typeof configuration === 'undefined') {
configuration = {};
}

assert.isInstance({configuration}, Configuration);
this.configuration = configuration;
}

/**
* Get the cache name
* @memberof module:sw-cache-expiration.Behavior
* @member {String} cacheName
*/
get cacheName() {
return this.configuration.cacheName;
}

/**
* Get the max cache entries.
* @return {Number} Returns the number of max entries
*/
get maxEntries() {
return this.configuration.maxEntries;
}

/**
* Get the max age for the cache entries.
* @return {Number} Max age in seconds for cache entries.
*/
get maxAgeSeconds() {
return this.configuration.maxAgeSeconds;
}

/**
* @private
* @return {idb} Get open idb.
*/
get db() {
if (!this._db) {
return idb.open(idbName, idbVersion, (upgradeDB) => {
Expand All @@ -48,15 +77,35 @@ export default class Behavior {
return Promise.resolve(this._db);
}

updateTimestamp(url, now = Date.now()) {
/**
* TODO updateTimestamp description
* @private
* @param {string} url
* @param {Number} now Defaults to current date.
* @return {Promise} Resolves once updated.
*/
updateTimestamp(url, now) {
if (typeof now === 'undefined') {
now = Date.now();
}

return this.db.then((db) => {
const tx = db.transaction(this.cacheName, 'readwrite');
tx.objectStore(this.cacheName).put(now, url);
return tx.complete;
});
}

expireEntries(now = Date.now()) {
/**
* TODO expireEntries description
* @param {Number} now Defaults to the current time
* @return {Promise} List of removed entries.
*/
expireEntries(now) {
if (typeof now === 'undefined') {
now = Date.now();
}

const promises = [];
promises.push(
this.maxAgeSeconds ? this._expireOldEntries(now) : Promise.resolve([]));
Expand All @@ -67,7 +116,17 @@ export default class Behavior {
.then(([oldEntries, extraEntries]) => oldEntries.concat(extraEntries));
}

_expireOldEntries(now = Date.now()) {
/**
* @private
* @param {Number} now
* @return {Promise<Array<String>>} Promise that resolves to an
* array of urls.
*/
_expireOldEntries(now) {
if (typeof now === 'undefined') {
now = Date.now();
}

const expireOlderThan = now - (this.maxAgeSeconds * 1000);
const urls = [];
return this.db.then((db) => {
Expand All @@ -87,7 +146,13 @@ export default class Behavior {
});
}

/**
* @private
* @return {Promise} Resolve to empty array.
*/
_expireExtraEntries() {
return Promise.resolve([]);
}
}

export default Behavior;
5 changes: 5 additions & 0 deletions projects/sw-routing/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
limitations under the License.
*/

/**
* sw-routing Module
* @module sw-routing
*/

import ExpressRoute from './lib/express-route';
import RegExpRoute from './lib/regexp-route';
import Route from './lib/route';
Expand Down
3 changes: 1 addition & 2 deletions projects/sw-routing/src/lib/express-route.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
limitations under the License.
*/

/** @module sw-routing.ExpressRoute **/

import Route from './route';
import assert from '../../../../lib/assert';
import pathToRegExp from 'path-to-regexp';
Expand All @@ -27,6 +25,7 @@ import pathToRegExp from 'path-to-regexp';
* library to transform the `path` parameter into a regular expression, which is
* then matched against the URL's path.
*
* @memberof module:sw-routing
* @extends Route
*/
class ExpressRoute extends Route {
Expand Down
3 changes: 1 addition & 2 deletions projects/sw-routing/src/lib/regexp-route.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@
limitations under the License.
*/

/** @module sw-routing.RegExpRoute **/

import Route from './route';
import assert from '../../../../lib/assert';

/**
* RegExpRoute is a helper class to make defining Regular Expression based
* [Routes]{@link Route} easy.
*
* @memberof module:sw-routing
* @extends Route
*/
class RegExpRoute extends Route {
Expand Down
Loading