Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 975f4da

Browse files
committedOct 27, 2020
docs: remove helpers
1 parent 62b6eae commit 975f4da

File tree

4 files changed

+89
-113
lines changed

4 files changed

+89
-113
lines changed
 

‎docs/content/en/api/helpers.md

-98
This file was deleted.

‎docs/content/en/examples/nuxt.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Nuxt Usage Example
33
menuTitle: Nuxt
44
description: 'Live example of Nuxt usage of Vue API Query on CodeSandbox.'
5-
position: 11
5+
position: 10
66
category: Examples
77
csb_link: https://codesandbox.io/embed/vue-api-query-nuxt-usage-example-9jhny?hidenavigation=1&theme=dark
88
fullscreen: true

‎docs/content/en/examples/vue.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Vue Usage Example
33
menuTitle: Vue
44
description: 'Live example of Vue usage of Vue API Query on CodeSandbox.'
5-
position: 12
5+
position: 11
66
category: Examples
77
csb_link: https://codesandbox.io/embed/vue-api-query-vue-usage-example-tvq4m?hidenavigation=1&theme=dark
88
fullscreen: true

‎docs/static/sw.js

+87-13
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,91 @@
1-
// THIS FILE SHOULD NOT BE VERSION CONTROLLED
1+
const options = {"workboxURL":"https://cdn.jsdelivr.net/npm/workbox-cdn@5.1.3/workbox/workbox-sw.js","importScripts":[],"config":{"debug":false},"clientsClaim":true,"skipWaiting":true,"cleanupOutdatedCaches":true,"offlineAnalytics":false,"preCaching":["/vue-api-query/?standalone=true"],"runtimeCaching":[{"urlPattern":"/vue-api-query/_nuxt/","handler":"CacheFirst","method":"GET","strategyPlugins":[]},{"urlPattern":"/vue-api-query/","handler":"NetworkFirst","method":"GET","strategyPlugins":[]}],"offlinePage":null,"pagesURLPattern":"/vue-api-query/","offlineStrategy":"NetworkFirst"}
22

3-
// https://github.com/NekR/self-destroying-sw
3+
importScripts(...[options.workboxURL, ...options.importScripts])
44

5-
self.addEventListener('install', function (e) {
6-
self.skipWaiting()
7-
})
5+
initWorkbox(workbox, options)
6+
workboxExtensions(workbox, options)
7+
precacheAssets(workbox, options)
8+
cachingExtensions(workbox, options)
9+
runtimeCaching(workbox, options)
10+
offlinePage(workbox, options)
11+
routingExtensions(workbox, options)
812

9-
self.addEventListener('activate', function (e) {
10-
self.registration.unregister()
11-
.then(function () {
12-
return self.clients.matchAll()
13-
})
14-
.then(function (clients) {
15-
clients.forEach(client => client.navigate(client.url))
13+
function getProp(obj, prop) {
14+
return prop.split('.').reduce((p, c) => p[c], obj)
15+
}
16+
17+
function initWorkbox(workbox, options) {
18+
if (options.config) {
19+
// Set workbox config
20+
workbox.setConfig(options.config)
21+
}
22+
23+
if (options.cacheNames) {
24+
// Set workbox cache names
25+
workbox.core.setCacheNameDetails(options.cacheNames)
26+
}
27+
28+
if (options.clientsClaim) {
29+
// Start controlling any existing clients as soon as it activates
30+
workbox.core.clientsClaim()
31+
}
32+
33+
if (options.skipWaiting) {
34+
workbox.core.skipWaiting()
35+
}
36+
37+
if (options.cleanupOutdatedCaches) {
38+
workbox.precaching.cleanupOutdatedCaches()
39+
}
40+
41+
if (options.offlineAnalytics) {
42+
// Enable offline Google Analytics tracking
43+
workbox.googleAnalytics.initialize()
44+
}
45+
}
46+
47+
function precacheAssets(workbox, options) {
48+
if (options.preCaching.length) {
49+
workbox.precaching.precacheAndRoute(options.preCaching, options.cacheOptions)
50+
}
51+
}
52+
53+
function runtimeCaching(workbox, options) {
54+
for (const entry of options.runtimeCaching) {
55+
const urlPattern = new RegExp(entry.urlPattern)
56+
const method = entry.method || 'GET'
57+
58+
const plugins = (entry.strategyPlugins || [])
59+
.map(p => new (getProp(workbox, p.use))(...p.config))
60+
61+
const strategyOptions = { ...entry.strategyOptions, plugins }
62+
63+
const strategy = new workbox.strategies[entry.handler](strategyOptions)
64+
65+
workbox.routing.registerRoute(urlPattern, strategy, method)
66+
}
67+
}
68+
69+
function offlinePage(workbox, options) {
70+
if (options.offlinePage) {
71+
// Register router handler for offlinePage
72+
workbox.routing.registerRoute(new RegExp(options.pagesURLPattern), ({ request, event }) => {
73+
const strategy = new workbox.strategies[options.offlineStrategy]
74+
return strategy
75+
.handle({ request, event })
76+
.catch(() => caches.match(options.offlinePage))
1677
})
17-
})
78+
}
79+
}
80+
81+
function workboxExtensions(workbox, options) {
82+
83+
}
84+
85+
function cachingExtensions(workbox, options) {
86+
87+
}
88+
89+
function routingExtensions(workbox, options) {
90+
91+
}

0 commit comments

Comments
 (0)
Please sign in to comment.