aboutsummaryrefslogtreecommitdiff
path: root/node_modules/vuepress/lib/app/SWUpdateEvent.js
diff options
context:
space:
mode:
authorruki <waruqi@gmail.com>2018-11-08 00:38:48 +0800
committerruki <waruqi@gmail.com>2018-11-07 21:53:09 +0800
commit26105034da4fcce7ac883c899d781f016559310d (patch)
treec459a5dc4e3aa0972d9919033ece511ce76dd129 /node_modules/vuepress/lib/app/SWUpdateEvent.js
parent2c77f00f1a7ecb6c8192f9c16d3b2001b254a107 (diff)
downloadxmake-docs-26105034da4fcce7ac883c899d781f016559310d.tar.gz
xmake-docs-26105034da4fcce7ac883c899d781f016559310d.zip
switch to vuepress
Diffstat (limited to 'node_modules/vuepress/lib/app/SWUpdateEvent.js')
-rw-r--r--node_modules/vuepress/lib/app/SWUpdateEvent.js43
1 files changed, 43 insertions, 0 deletions
diff --git a/node_modules/vuepress/lib/app/SWUpdateEvent.js b/node_modules/vuepress/lib/app/SWUpdateEvent.js
new file mode 100644
index 00000000..fe6ab31c
--- /dev/null
+++ b/node_modules/vuepress/lib/app/SWUpdateEvent.js
@@ -0,0 +1,43 @@
+export default class SWUpdateEvent {
+ constructor (registration) {
+ Object.defineProperty(this, 'registration', {
+ value: registration,
+ configurable: true,
+ writable: true
+ })
+ }
+
+ /**
+ * Check if the new service worker exists or not.
+ */
+ update () {
+ return this.registration.update()
+ }
+
+ /**
+ * Activate new service worker to work 'location.reload()' with new data.
+ */
+ skipWaiting () {
+ const worker = this.registration.waiting
+ if (!worker) {
+ return Promise.resolve()
+ }
+
+ console.log('[vuepress:sw] Doing worker.skipWaiting().')
+ return new Promise((resolve, reject) => {
+ const channel = new MessageChannel()
+
+ channel.port1.onmessage = (event) => {
+ console.log('[vuepress:sw] Done worker.skipWaiting().')
+ if (event.data.error) {
+ reject(event.data.error)
+ } else {
+ resolve(event.data)
+ }
+ }
+
+ worker.postMessage({ type: 'skip-waiting' }, [channel.port2])
+ })
+ }
+}
+