@cocreate/pwa 1.2.6 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,23 @@
1
+ # [1.3.0](https://github.com/CoCreate-app/CoCreate-pwa/compare/v1.2.7...v1.3.0) (2022-11-21)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * commented console.logs ([38851a5](https://github.com/CoCreate-app/CoCreate-pwa/commit/38851a5fcae5b4d650811a3e9e04d01a702cdfd9))
7
+ * ignore dist ([091e426](https://github.com/CoCreate-app/CoCreate-pwa/commit/091e426599af0a1637c9f4797e73c56cc46062ae))
8
+
9
+
10
+ ### Features
11
+
12
+ * if cached return cache then request and store to get current version fto apply on next reload ([49ef323](https://github.com/CoCreate-app/CoCreate-pwa/commit/49ef323964187a136734179c94d002bbfabb30f8))
13
+
14
+ ## [1.2.7](https://github.com/CoCreate-app/CoCreate-pwa/compare/v1.2.6...v1.2.7) (2022-10-02)
15
+
16
+
17
+ ### Bug Fixes
18
+
19
+ * minor bug fixes ([23713fe](https://github.com/CoCreate-app/CoCreate-pwa/commit/23713fe7b1726cc8685db16084ac4b253f78e387))
20
+
1
21
  ## [1.2.6](https://github.com/CoCreate-app/CoCreate-pwa/compare/v1.2.5...v1.2.6) (2022-10-02)
2
22
 
3
23
 
package/demo/sw.js CHANGED
@@ -4,7 +4,8 @@ const CACHE_INMUTABLE_NAME = "inmutable-v1";
4
4
  const CACHE_TEMP = 'temp-cache';
5
5
  const CACHE_DYNAMIC_LIMIT = 50;
6
6
  const fetchedMap = []
7
-
7
+ const cacheType = 'cache'
8
+ const requestMap = new Map()
8
9
 
9
10
  function deleteCache(key) {
10
11
  return caches.delete(key);
@@ -31,7 +32,7 @@ self.addEventListener("activate", async (e) => {
31
32
 
32
33
  // e.waitUntil(updateCache())
33
34
  // updateCache()
34
-
35
+ e.waitUntil(clients.claim());
35
36
  });
36
37
 
37
38
  self.addEventListener("fetch", (e) => {
@@ -40,23 +41,35 @@ self.addEventListener("fetch", (e) => {
40
41
  caches
41
42
  .match(e.request)
42
43
  .then((cachesObj) => {
43
- if (!navigator.onLine && !!cachesObj) {
44
+ if (!navigator.onLine && !!cachesObj)
44
45
  return cachesObj;
45
- }
46
- return fetch(e.request)
47
- .then((newResp) => {
48
- caches
49
- .open(CACHE_DYNAMIC_NAME)
50
- .then((cache) => {
46
+
47
+ if (cacheType == 'cache' && !!cachesObj) {
48
+ // console.log('returned from cache')
49
+ requestMap.set(cachesObj, '')
50
+ fetch(e.request).then((newResp) => {
51
+ caches.open(CACHE_DYNAMIC_NAME).then((cache) => {
51
52
  cache.put(e.request, newResp);
52
53
  // cleanCache(CACHE_DYNAMIC_NAME, CACHE_DYNAMIC_LIMIT);
53
- })
54
- .catch(() => {});
55
- return newResp.clone();
56
- })
57
- .catch(() => {
54
+ }).catch(() => {
55
+
56
+ });
57
+ }).catch(() => {
58
58
  return caches.match('./offline.html');
59
59
  })
60
+ return cachesObj;
61
+ } else {
62
+ return fetch(e.request).then((newResp) => {
63
+ caches.open(CACHE_DYNAMIC_NAME).then((cache) => {
64
+ cache.put(e.request, newResp);
65
+ // cleanCache(CACHE_DYNAMIC_NAME, CACHE_DYNAMIC_LIMIT);
66
+ }).catch(() => {});
67
+ return newResp.clone();
68
+ })
69
+ .catch(() => {
70
+ return caches.match('./offline.html');
71
+ })
72
+ }
60
73
  })
61
74
  .catch(function() {
62
75
  console.log('Fetch failed retuned offline page! ')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/pwa",
3
- "version": "1.2.6",
3
+ "version": "1.3.0",
4
4
  "description": "A simple pwa component in vanilla javascript. Easily configured using HTML5 data-attributes and/or JavaScript API.",
5
5
  "keywords": [
6
6
  "pwa",
@@ -60,6 +60,6 @@
60
60
  "webpack-log": "^3.0.1"
61
61
  },
62
62
  "dependencies": {
63
- "@cocreate/docs": "^1.3.16"
63
+ "@cocreate/docs": "^1.3.17"
64
64
  }
65
65
  }
package/src/index.js CHANGED
@@ -16,7 +16,7 @@ const button = document.querySelector('[actions*="install"]');
16
16
  // }
17
17
 
18
18
  window.addEventListener('beforeinstallprompt', (event) => {
19
- console.log('👍', 'beforeinstallprompt', event);
19
+ // console.log('👍', 'beforeinstallprompt', event);
20
20
  // Stash the event so it can be triggered later.
21
21
  window.deferredPrompt = event;
22
22
  // Remove the 'hidden' class from the install button container
@@ -26,7 +26,7 @@ window.addEventListener('beforeinstallprompt', (event) => {
26
26
 
27
27
  if (button) {
28
28
  button.addEventListener('click', async() => {
29
- console.log('👍', 'installBtn-clicked');
29
+ // console.log('👍', 'installBtn-clicked');
30
30
  const promptEvent = window.deferredPrompt;
31
31
  if (!promptEvent) {
32
32
  // The deferred prompt isn't available.
@@ -46,7 +46,7 @@ if (button) {
46
46
  }
47
47
 
48
48
  window.addEventListener('appinstalled', (event) => {
49
- console.log('👍', 'appinstalled', event);
49
+ // console.log('👍', 'appinstalled', event);
50
50
  // Clear the deferredPrompt so it can be garbage collected
51
51
  window.deferredPrompt = null;
52
52
  });
@@ -54,7 +54,7 @@ window.addEventListener('appinstalled', (event) => {
54
54
  async function persistData() {
55
55
  if (navigator.storage && navigator.storage.persist) {
56
56
  const result = await navigator.storage.persist();
57
- console.log(`Data persisted: ${result}`);
57
+ // console.log(`Data persisted: ${result}`);
58
58
  }
59
59
  }
60
60
 
@@ -81,7 +81,7 @@ if ('serviceWorker' in navigator) {
81
81
  reg.onupdatefound = () => {
82
82
  const installingWorker = reg.installing;
83
83
  installingWorker.onstatechange = () => {
84
- console.log('Service Worker', installingWorker.state);
84
+ // console.log('Service Worker', installingWorker.state);
85
85
  }
86
86
  }
87
87
  })