From 2b3cf15d60ae94039f3fdf41114a307b8d2acca6 Mon Sep 17 00:00:00 2001 From: Matt Gaunt Date: Fri, 4 Nov 2016 14:18:09 -0700 Subject: [PATCH 1/3] Adding current changes to the jsdoc --- .ruby-version | 1 + Gemfile | 5 +++++ docs/_config.yml | 6 ++++++ docs/index.md | 4 ++++ jsdoc.conf | 19 +++++++++++++++++ package.json | 1 + .../sw-broadcast-cache-update/src/index.js | 8 ++++--- .../src/lib/behavior.js | 17 ++++++++------- .../src/lib/broadcast-update.js | 14 ++++++++----- .../src/lib/constants.js | 19 ++++++++++------- .../src/lib/responses-are-same.js | 10 ++++++--- projects/sw-routing/src/index.js | 5 +++++ projects/sw-routing/src/lib/regexp-route.js | 3 +-- projects/sw-routing/src/lib/route.js | 4 ++-- projects/sw-routing/src/lib/router.js | 21 ++++++++++++++++++- .../sw-runtime-caching/src/lib/cache-first.js | 4 +++- 16 files changed, 110 insertions(+), 31 deletions(-) create mode 100644 .ruby-version create mode 100644 Gemfile create mode 100644 docs/_config.yml create mode 100644 docs/index.md create mode 100644 jsdoc.conf diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 000000000..76521af31 --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +ruby-2.2.0 diff --git a/Gemfile b/Gemfile new file mode 100644 index 000000000..9bb07b405 --- /dev/null +++ b/Gemfile @@ -0,0 +1,5 @@ +source "http://rubygems.org" + +gem 'jekyll', '>=3.1.6' +gem 'kramdown' +gem 'jekyll-github-metadata' diff --git a/docs/_config.yml b/docs/_config.yml new file mode 100644 index 000000000..a26bcfed3 --- /dev/null +++ b/docs/_config.yml @@ -0,0 +1,6 @@ +source: . +layouts_dir: ./themes/jekyll/_layouts/ +includes_dir: ./themes/jekyll/_includes/ + +# This adds github pages data +gems: ['jekyll-github-metadata'] diff --git a/docs/index.md b/docs/index.md new file mode 100644 index 000000000..773b4d3ab --- /dev/null +++ b/docs/index.md @@ -0,0 +1,4 @@ +--- +layout: index +navigation_weight: 0 +--- diff --git a/jsdoc.conf b/jsdoc.conf new file mode 100644 index 000000000..0d4ae8c96 --- /dev/null +++ b/jsdoc.conf @@ -0,0 +1,19 @@ +{ + "source": { + "include": [ + "./projects" + ], + "excludePattern": "(^|\\/|\\\\)build(\\/|\\\\)" + }, + "plugins": [ + "node_modules/jsdoc-strip-async-await", + "plugins/markdown" + ], + "opts": { + "template": "node_modules/npm-publish-scripts/build/themes/jsdoc", + "recurse": true + }, + "markdown": { + "idInHeadings": true + } +} diff --git a/package.json b/package.json index fb61dcc7b..651c2446b 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/projects/sw-broadcast-cache-update/src/index.js b/projects/sw-broadcast-cache-update/src/index.js index 447634229..ada2bebd8 100644 --- a/projects/sw-broadcast-cache-update/src/index.js +++ b/projects/sw-broadcast-cache-update/src/index.js @@ -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, diff --git a/projects/sw-broadcast-cache-update/src/lib/behavior.js b/projects/sw-broadcast-cache-update/src/lib/behavior.js index 6674865ff..2c71d95be 100644 --- a/projects/sw-broadcast-cache-update/src/lib/behavior.js +++ b/projects/sw-broadcast-cache-update/src/lib/behavior.js @@ -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: * @@ -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.} [$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} 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. @@ -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. diff --git a/projects/sw-broadcast-cache-update/src/lib/broadcast-update.js b/projects/sw-broadcast-cache-update/src/lib/broadcast-update.js index 9ee49957c..90bafa7ee 100644 --- a/projects/sw-broadcast-cache-update/src/lib/broadcast-update.js +++ b/projects/sw-broadcast-cache-update/src/lib/broadcast-update.js @@ -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); diff --git a/projects/sw-broadcast-cache-update/src/lib/constants.js b/projects/sw-broadcast-cache-update/src/lib/constants.js index d96f1a4a7..428460e5a 100644 --- a/projects/sw-broadcast-cache-update/src/lib/constants.js +++ b/projects/sw-broadcast-cache-update/src/lib/constants.js @@ -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.} The default headers to compare when determining - * whether two `Response` objects are different. + * @type {Array} */ const defaultHeadersToCheck = [ 'content-length', @@ -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'; diff --git a/projects/sw-broadcast-cache-update/src/lib/responses-are-same.js b/projects/sw-broadcast-cache-update/src/lib/responses-are-same.js index 5df1afd8d..ff9441bf6 100644 --- a/projects/sw-broadcast-cache-update/src/lib/responses-are-same.js +++ b/projects/sw-broadcast-cache-update/src/lib/responses-are-same.js @@ -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.} $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} 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. diff --git a/projects/sw-routing/src/index.js b/projects/sw-routing/src/index.js index 56647a202..1353ad140 100644 --- a/projects/sw-routing/src/index.js +++ b/projects/sw-routing/src/index.js @@ -13,6 +13,11 @@ limitations under the License. */ +/** + * sw-routing Module + * @module sw-routing + */ + import * as predicates from './lib/predicates'; import RegExpRoute from './lib/regexp-route'; import Route from './lib/route'; diff --git a/projects/sw-routing/src/lib/regexp-route.js b/projects/sw-routing/src/lib/regexp-route.js index 8e56959d2..0a16e8ad5 100644 --- a/projects/sw-routing/src/lib/regexp-route.js +++ b/projects/sw-routing/src/lib/regexp-route.js @@ -13,8 +13,6 @@ limitations under the License. */ -/** @module sw-routing.RegExpRoute **/ - import Route from './route'; import assert from '../../../../lib/assert'; @@ -22,6 +20,7 @@ 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 { diff --git a/projects/sw-routing/src/lib/route.js b/projects/sw-routing/src/lib/route.js index 1b65e018c..c691ac7e2 100644 --- a/projects/sw-routing/src/lib/route.js +++ b/projects/sw-routing/src/lib/route.js @@ -13,8 +13,6 @@ limitations under the License. */ -/** @module sw-routing.Route **/ - import assert from '../../../../lib/assert'; import {defaultMethod, validMethods} from './constants'; @@ -28,6 +26,8 @@ import {defaultMethod, validMethods} from './constants'; * current request), then the handler will be given the * [FetchEvent](https://developer.mozilla.org/en-US/docs/Web/API/FetchEvent) * so that it can respond to the request. + * + * @memberof module:sw-routing */ class Route { /** diff --git a/projects/sw-routing/src/lib/router.js b/projects/sw-routing/src/lib/router.js index 78653198e..2e0e493db 100644 --- a/projects/sw-routing/src/lib/router.js +++ b/projects/sw-routing/src/lib/router.js @@ -19,14 +19,28 @@ import assert from '../../../../lib/assert'; /** * The Router takes a set of {@link Route}'s and will direct fetch events * to those Route in the order they are registered. + * + * @memberof module:sw-routing */ class Router { + /** + * A default handler will have it's handle method called when a + * request doesn't have a matching route. + * @param {Object} input + * @param {Handler} input.handler A handler to deal with default routes. + */ setDefaultHandler({handler} = {}) { assert.hasMethod({handler}, 'handle'); this.defaultHandler = handler; } + /** + * If a Route throws an error while handling a request, this catch handler + * will be called to return an error case. + * @param {Object} input + * @param {Handler} input.handler A handler to deal with errors in routes. + */ setCatchHandler({handler} = {}) { assert.hasMethod({handler}, 'handle'); @@ -39,7 +53,7 @@ class Router { * * @param {Object} options * @param {Array} options.routes - * @returns {void} + * @return {void} */ registerRoutes({routes} = {}) { assert.isInstance({routes}, Array); @@ -83,6 +97,11 @@ class Router { }); } + /** + * Registers a route with the router. + * @param {Object} input + * @param {Route} input.route The route to register. + */ registerRoute({route} = {}) { assert.isInstance({route}, Route); diff --git a/projects/sw-runtime-caching/src/lib/cache-first.js b/projects/sw-runtime-caching/src/lib/cache-first.js index 5c5abe968..ade0abd63 100644 --- a/projects/sw-runtime-caching/src/lib/cache-first.js +++ b/projects/sw-runtime-caching/src/lib/cache-first.js @@ -16,7 +16,7 @@ import Handler from './handler'; import assert from '../../../../lib/assert'; -export default class CacheFirst extends Handler { +class CacheFirst extends Handler { async handle({event} = {}) { assert.isInstance({event}, FetchEvent); @@ -29,3 +29,5 @@ export default class CacheFirst extends Handler { }); } } + +export default CacheFirst; From 6ebcfd27747c8a2ed4e77409362822626c48773a Mon Sep 17 00:00:00 2001 From: Matt Gaunt Date: Fri, 4 Nov 2016 15:16:56 -0700 Subject: [PATCH 2/3] Fixing up modules and JSDoc --- jsdoc.conf | 2 +- projects/sw-cache-expiration/src/index.js | 5 ++ .../sw-cache-expiration/src/lib/behavior.js | 75 +++++++++++++++++-- projects/sw-routing/src/lib/express-route.js | 3 +- projects/sw-runtime-caching/src/index.js | 5 ++ .../sw-runtime-caching/src/lib/cache-first.js | 7 ++ .../sw-runtime-caching/src/lib/cache-only.js | 11 ++- .../sw-runtime-caching/src/lib/constants.js | 5 ++ .../sw-runtime-caching/src/lib/handler.js | 14 +++- .../src/lib/network-first.js | 11 ++- .../src/lib/network-only.js | 10 ++- .../src/lib/request-wrapper.js | 32 +++++++- .../src/lib/stale-while-revalidate.js | 11 ++- 13 files changed, 174 insertions(+), 17 deletions(-) diff --git a/jsdoc.conf b/jsdoc.conf index 0d4ae8c96..cdf237ebf 100644 --- a/jsdoc.conf +++ b/jsdoc.conf @@ -3,7 +3,7 @@ "include": [ "./projects" ], - "excludePattern": "(^|\\/|\\\\)build(\\/|\\\\)" + "excludePattern": "((^|\\/|\\\\)build(\\/|\\\\)|(^|\\/|\\\\)test(\\/|\\\\))" }, "plugins": [ "node_modules/jsdoc-strip-async-await", diff --git a/projects/sw-cache-expiration/src/index.js b/projects/sw-cache-expiration/src/index.js index 0c05f13ab..63b5530e9 100644 --- a/projects/sw-cache-expiration/src/index.js +++ b/projects/sw-cache-expiration/src/index.js @@ -13,6 +13,11 @@ limitations under the License. */ +/** + * sw-cache-expiration Module + * @module sw-cache-expiration + */ + import Behavior from './lib/behavior'; export {Behavior}; diff --git a/projects/sw-cache-expiration/src/lib/behavior.js b/projects/sw-cache-expiration/src/lib/behavior.js index 43440ea4d..5b1409705 100644 --- a/projects/sw-cache-expiration/src/lib/behavior.js +++ b/projects/sw-cache-expiration/src/lib/behavior.js @@ -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) => { @@ -48,7 +77,18 @@ 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); @@ -56,7 +96,16 @@ export default class Behavior { }); } - 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([])); @@ -67,7 +116,17 @@ export default class Behavior { .then(([oldEntries, extraEntries]) => oldEntries.concat(extraEntries)); } - _expireOldEntries(now = Date.now()) { + /** + * @private + * @param {Number} now + * @return {Promise>} 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) => { @@ -87,7 +146,13 @@ export default class Behavior { }); } + /** + * @private + * @return {Promise} Resolve to empty array. + */ _expireExtraEntries() { return Promise.resolve([]); } } + +export default Behavior; diff --git a/projects/sw-routing/src/lib/express-route.js b/projects/sw-routing/src/lib/express-route.js index 2a0a71393..9511ebb2c 100644 --- a/projects/sw-routing/src/lib/express-route.js +++ b/projects/sw-routing/src/lib/express-route.js @@ -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'; @@ -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 { diff --git a/projects/sw-runtime-caching/src/index.js b/projects/sw-runtime-caching/src/index.js index 0296fe619..96d40e4fd 100644 --- a/projects/sw-runtime-caching/src/index.js +++ b/projects/sw-runtime-caching/src/index.js @@ -13,6 +13,11 @@ limitations under the License. */ +/** + * sw-runtime-caching Module + * @module sw-runtime-caching + */ + import RequestWrapper from './lib/request-wrapper'; import CacheFirst from './lib/cache-first'; import CacheOnly from './lib/cache-only'; diff --git a/projects/sw-runtime-caching/src/lib/cache-first.js b/projects/sw-runtime-caching/src/lib/cache-first.js index ade0abd63..4ef992d13 100644 --- a/projects/sw-runtime-caching/src/lib/cache-first.js +++ b/projects/sw-runtime-caching/src/lib/cache-first.js @@ -16,7 +16,14 @@ import Handler from './handler'; import assert from '../../../../lib/assert'; +/** + * @memberof module:sw-runtime-caching + * @extends module:sw-runtime-caching.Handler + */ class CacheFirst extends Handler { + /** + * @return {Promise} Returns cached response. + */ async handle({event} = {}) { assert.isInstance({event}, FetchEvent); diff --git a/projects/sw-runtime-caching/src/lib/cache-only.js b/projects/sw-runtime-caching/src/lib/cache-only.js index b02ad1f3c..9d0911190 100644 --- a/projects/sw-runtime-caching/src/lib/cache-only.js +++ b/projects/sw-runtime-caching/src/lib/cache-only.js @@ -16,10 +16,19 @@ import Handler from './handler'; import assert from '../../../../lib/assert'; -export default class CacheOnly extends Handler { +/** + * @memberof module:sw-runtime-caching + * @extends module:sw-runtime-caching.Handler + */ +class CacheOnly extends Handler { + /** + * @return {Promise} The cached response. + */ async handle({event} = {}) { assert.isInstance({event}, FetchEvent); return await this.requestWrapper.match({request: event.request}); } } + +export default CacheOnly; diff --git a/projects/sw-runtime-caching/src/lib/constants.js b/projects/sw-runtime-caching/src/lib/constants.js index 709bac6db..439eee804 100644 --- a/projects/sw-runtime-caching/src/lib/constants.js +++ b/projects/sw-runtime-caching/src/lib/constants.js @@ -13,6 +13,11 @@ limitations under the License. */ +/** + * TODO defaultCacheName description + * @type {string} + * @memberof module:sw-runtime-caching + */ export const defaultCacheName = `sw-runtime-caching-${self.registration.scope}`; export const behaviorCallbacks = [ 'cacheDidUpdate', diff --git a/projects/sw-runtime-caching/src/lib/handler.js b/projects/sw-runtime-caching/src/lib/handler.js index c2b66b754..96f3e5171 100644 --- a/projects/sw-runtime-caching/src/lib/handler.js +++ b/projects/sw-runtime-caching/src/lib/handler.js @@ -13,14 +13,17 @@ limitations under the License. */ -/** @module sw-runtime-caching.Handler **/ - import RequestWrapper from './request-wrapper'; /** * The Handler class... + * @memberof module:sw-runtime-caching */ -export default class Handler { +class Handler { + /** + * @param {Object} input + * @param {RequestWrapper} [input.requestWrapper] + */ constructor({requestWrapper} = {}) { if (requestWrapper) { this.requestWrapper = requestWrapper; @@ -32,11 +35,14 @@ export default class Handler { /** * An abstract method that must be overriden in a subclass. * + * @abstract * @param {FetchEvent} event - The event triggered by a network request. * @param {Object} params - Any parameters passed in via the when predicate. - * @returns {Promise} - The Response used to fulfill the request. + * @return {Promise} - The Response used to fulfill the request. */ handle({event, params} = {}) { throw Error('This abstract method must be overridden in a subclass.'); } } + +export default Handler; diff --git a/projects/sw-runtime-caching/src/lib/network-first.js b/projects/sw-runtime-caching/src/lib/network-first.js index b2b26cd03..7860ed028 100644 --- a/projects/sw-runtime-caching/src/lib/network-first.js +++ b/projects/sw-runtime-caching/src/lib/network-first.js @@ -16,7 +16,14 @@ import Handler from './handler'; import assert from '../../../../lib/assert'; -export default class NetworkFirst extends Handler { +/** + * @memberof module:sw-runtime-caching + * @extends module:sw-runtime-caching.Handler + */ +class NetworkFirst extends Handler { + /** + * @return {Promise} The network response. + */ async handle({event} = {}) { assert.isInstance({event}, FetchEvent); @@ -35,3 +42,5 @@ export default class NetworkFirst extends Handler { return await this.requestWrapper.match({request: event.request}); } } + +export default NetworkFirst; diff --git a/projects/sw-runtime-caching/src/lib/network-only.js b/projects/sw-runtime-caching/src/lib/network-only.js index 3102ba318..c0f9db9ad 100644 --- a/projects/sw-runtime-caching/src/lib/network-only.js +++ b/projects/sw-runtime-caching/src/lib/network-only.js @@ -16,10 +16,18 @@ import Handler from './handler'; import assert from '../../../../lib/assert'; -export default class NetworkOnly extends Handler { +/** + * @memberof module:sw-runtime-caching + */ +class NetworkOnly extends Handler { + /** + * @return {Promise} The network response. + */ async handle({event} = {}) { assert.isInstance({event}, FetchEvent); return await this.requestWrapper.fetch({request: event.request}); } } + +export default NetworkOnly; diff --git a/projects/sw-runtime-caching/src/lib/request-wrapper.js b/projects/sw-runtime-caching/src/lib/request-wrapper.js index ef85fa505..ca1986c15 100644 --- a/projects/sw-runtime-caching/src/lib/request-wrapper.js +++ b/projects/sw-runtime-caching/src/lib/request-wrapper.js @@ -16,7 +16,17 @@ import assert from '../../../../lib/assert'; import {behaviorCallbacks, defaultCacheName} from './constants'; -export default class RequestWrapper { +/** + * @memberof module:sw-runtime-caching + */ +class RequestWrapper { + /** + * @param {Object} input + * @param {String} input.cacheName + * @param {Array} input.behaviors + * @param {Object} input.fetchOptions + * @oaram {Object} input.matchOptions + */ constructor({cacheName, behaviors, fetchOptions, matchOptions} = {}) { if (cacheName) { assert.isType({cacheName}, 'string'); @@ -54,6 +64,9 @@ export default class RequestWrapper { } } + /** + * @return {Cache} The cache for this RequestWrapper. + */ async getCache() { if (!this._cache) { this._cache = await caches.open(this.cacheName); @@ -61,6 +74,11 @@ export default class RequestWrapper { return this._cache; } + /** + * @param {Object} input + * @param {Request} input.request + * @return {Promise} The cache response. + */ async match({request}) { assert.atLeastOne({request}); @@ -68,6 +86,11 @@ export default class RequestWrapper { return await cache.match(request, this.matchOptions); } + /** + * @param {Object} input + * @param {Request} input.request + * @return {Promise} The network response. + */ async fetch({request}) { assert.atLeastOne({request}); @@ -82,6 +105,11 @@ export default class RequestWrapper { }); } + /** + * @param {Object} input + * @param {Request} input.request + * @return {Promise} The network response. + */ async fetchAndCache({request}) { assert.atLeastOne({request}); @@ -119,3 +147,5 @@ export default class RequestWrapper { return response; } } + +export default RequestWrapper; diff --git a/projects/sw-runtime-caching/src/lib/stale-while-revalidate.js b/projects/sw-runtime-caching/src/lib/stale-while-revalidate.js index 919884125..eefe71805 100644 --- a/projects/sw-runtime-caching/src/lib/stale-while-revalidate.js +++ b/projects/sw-runtime-caching/src/lib/stale-while-revalidate.js @@ -16,7 +16,14 @@ import Handler from './handler'; import assert from '../../../../lib/assert'; -export default class StaleWhileRevalidate extends Handler { +/** + * @memberof module:sw-runtime-caching + * @extends module:sw-runtime-caching.Handler + */ +class StaleWhileRevalidate extends Handler { + /** + * @return {Promise} The response for cached / fetched response. + */ async handle({event} = {}) { assert.isInstance({event}, FetchEvent); @@ -30,3 +37,5 @@ export default class StaleWhileRevalidate extends Handler { return cachedResponse || await fetchAndCacheResponse; } } + +export default StaleWhileRevalidate; From d9a6a031e7f40cedd385fe89e6c82bc05a9b7568 Mon Sep 17 00:00:00 2001 From: Matt Gaunt Date: Sat, 5 Nov 2016 10:53:37 -0700 Subject: [PATCH 3/3] Bumping selenium-assistant version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5403fcdf4..b50f5ebdf 100644 --- a/package.json +++ b/package.json @@ -57,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"