valyrian.js 7.2.11 → 8.0.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/README.md +6 -6
- package/dist/flux-store/index.d.ts +32 -0
- package/dist/flux-store/index.d.ts.map +1 -0
- package/dist/flux-store/index.js +258 -0
- package/dist/flux-store/index.js.map +7 -0
- package/dist/flux-store/index.min.js +1 -0
- package/dist/flux-store/index.min.js.map +1 -0
- package/dist/flux-store/index.mjs +237 -0
- package/dist/flux-store/index.mjs.map +7 -0
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +42 -75
- package/dist/hooks/index.js.map +2 -2
- package/dist/hooks/index.min.js +1 -0
- package/dist/hooks/index.min.js.map +1 -0
- package/dist/hooks/index.mjs +43 -76
- package/dist/hooks/index.mjs.map +2 -2
- package/dist/index.d.ts +52 -54
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +397 -328
- package/dist/index.js.map +3 -3
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/index.mjs +397 -328
- package/dist/index.mjs.map +3 -3
- package/dist/native-store/index.d.ts +14 -0
- package/dist/native-store/index.d.ts.map +1 -0
- package/dist/native-store/index.js +103 -0
- package/dist/native-store/index.js.map +7 -0
- package/dist/native-store/index.min.js +1 -0
- package/dist/native-store/index.min.js.map +1 -0
- package/dist/native-store/index.mjs +82 -0
- package/dist/native-store/index.mjs.map +7 -0
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +223 -86
- package/dist/node/index.js.map +4 -4
- package/dist/node/index.mjs +223 -86
- package/dist/node/index.mjs.map +4 -4
- package/dist/node/node.sw.js +152 -0
- package/dist/node/utils/inline.d.ts.map +1 -1
- package/dist/node/utils/node.sw.js +152 -0
- package/dist/node/utils/session-storage.d.ts +22 -0
- package/dist/node/utils/session-storage.d.ts.map +1 -0
- package/dist/node/utils/sw.d.ts.map +1 -1
- package/dist/node/utils/tree-adapter.d.ts +9 -0
- package/dist/node/utils/tree-adapter.d.ts.map +1 -1
- package/dist/pulse-store/index.d.ts +13 -0
- package/dist/pulse-store/index.d.ts.map +1 -0
- package/dist/pulse-store/index.js +143 -0
- package/dist/pulse-store/index.js.map +7 -0
- package/dist/pulse-store/index.min.js +1 -0
- package/dist/pulse-store/index.min.js.map +1 -0
- package/dist/pulse-store/index.mjs +122 -0
- package/dist/pulse-store/index.mjs.map +7 -0
- package/dist/request/index.d.ts.map +1 -1
- package/dist/request/index.js +68 -89
- package/dist/request/index.js.map +2 -2
- package/dist/request/index.min.js +1 -0
- package/dist/request/index.min.js.map +1 -0
- package/dist/request/index.mjs +68 -89
- package/dist/request/index.mjs.map +2 -2
- package/dist/router/index.d.ts +32 -31
- package/dist/router/index.d.ts.map +1 -1
- package/dist/router/index.js +256 -104
- package/dist/router/index.js.map +3 -3
- package/dist/router/index.min.js +1 -0
- package/dist/router/index.min.js.map +1 -0
- package/dist/router/index.mjs +256 -104
- package/dist/router/index.mjs.map +3 -3
- package/dist/signals/index.d.ts +6 -0
- package/dist/signals/index.d.ts.map +1 -0
- package/dist/signals/index.js +92 -0
- package/dist/signals/index.js.map +7 -0
- package/dist/signals/index.min.js +1 -0
- package/dist/signals/index.min.js.map +1 -0
- package/dist/signals/index.mjs +71 -0
- package/dist/signals/index.mjs.map +7 -0
- package/dist/suspense/index.d.ts +6 -0
- package/dist/suspense/index.d.ts.map +1 -0
- package/dist/suspense/index.js +67 -0
- package/dist/suspense/index.js.map +7 -0
- package/dist/suspense/index.min.js +1 -0
- package/dist/suspense/index.min.js.map +1 -0
- package/dist/suspense/index.mjs +46 -0
- package/dist/suspense/index.mjs.map +7 -0
- package/dist/sw/index.min.js +1 -0
- package/dist/sw/index.min.js.map +1 -0
- package/dist/translate/index.d.ts +19 -0
- package/dist/translate/index.d.ts.map +1 -0
- package/dist/translate/index.js +150 -0
- package/dist/translate/index.js.map +7 -0
- package/dist/translate/index.min.js +1 -0
- package/dist/translate/index.min.js.map +1 -0
- package/dist/translate/index.mjs +129 -0
- package/dist/translate/index.mjs.map +7 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/deep-freeze.d.ts +3 -0
- package/dist/utils/deep-freeze.d.ts.map +1 -0
- package/dist/utils/getter-setter.d.ts +3 -0
- package/dist/utils/getter-setter.d.ts.map +1 -0
- package/dist/utils/has-changed.d.ts +2 -0
- package/dist/utils/has-changed.d.ts.map +1 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +138 -0
- package/dist/utils/index.js.map +7 -0
- package/dist/utils/index.min.js +1 -0
- package/dist/utils/index.min.js.map +1 -0
- package/dist/utils/index.mjs +115 -0
- package/dist/utils/index.mjs.map +7 -0
- package/lib/flux-store/index.ts +301 -0
- package/lib/hooks/index.ts +52 -101
- package/lib/index.ts +479 -719
- package/lib/native-store/index.ts +106 -0
- package/lib/node/index.ts +5 -3
- package/lib/node/utils/icons.ts +5 -5
- package/lib/node/utils/inline.ts +17 -17
- package/lib/node/utils/node.sw.js +152 -0
- package/lib/node/utils/session-storage.ts +117 -0
- package/lib/node/utils/sw.ts +35 -11
- package/lib/node/utils/tree-adapter.ts +99 -52
- package/lib/pulse-store/index.ts +181 -0
- package/lib/request/index.ts +86 -116
- package/lib/router/index.ts +358 -170
- package/lib/signals/index.ts +98 -0
- package/lib/suspense/index.ts +57 -0
- package/lib/translate/index.ts +156 -0
- package/lib/utils/deep-freeze.ts +54 -0
- package/lib/utils/getter-setter.ts +40 -0
- package/lib/utils/has-changed.ts +43 -0
- package/lib/utils/index.ts +3 -0
- package/package.json +38 -50
- package/tsconfig.json +1 -1
- package/dist/dataset/index.d.ts +0 -24
- package/dist/dataset/index.d.ts.map +0 -1
- package/dist/dataset/index.js +0 -178
- package/dist/dataset/index.js.map +0 -7
- package/dist/dataset/index.mjs +0 -157
- package/dist/dataset/index.mjs.map +0 -7
- package/dist/node/node.sw.tpl +0 -133
- package/dist/node/utils/node.sw.tpl +0 -133
- package/dist/proxy-signal/index.d.ts +0 -23
- package/dist/proxy-signal/index.d.ts.map +0 -1
- package/dist/proxy-signal/index.js +0 -138
- package/dist/proxy-signal/index.js.map +0 -7
- package/dist/proxy-signal/index.mjs +0 -117
- package/dist/proxy-signal/index.mjs.map +0 -7
- package/dist/signal/index.d.ts +0 -20
- package/dist/signal/index.d.ts.map +0 -1
- package/dist/signal/index.js +0 -95
- package/dist/signal/index.js.map +0 -7
- package/dist/signal/index.mjs +0 -74
- package/dist/signal/index.mjs.map +0 -7
- package/dist/store/index.d.ts +0 -16
- package/dist/store/index.d.ts.map +0 -1
- package/dist/store/index.js +0 -93
- package/dist/store/index.js.map +0 -7
- package/dist/store/index.mjs +0 -72
- package/dist/store/index.mjs.map +0 -7
- package/lib/dataset/index.ts +0 -193
- package/lib/index.d.ts +0 -0
- package/lib/interfaces.ts.bak +0 -141
- package/lib/node/utils/node.sw.tpl +0 -133
- package/lib/proxy-signal/index.ts +0 -187
- package/lib/signal/index.ts +0 -161
- package/lib/store/index.ts +0 -101
package/dist/store/index.js.map
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../lib/store/index.ts"],
|
|
4
|
-
"sourcesContent": ["import { update } from \"valyrian.js\";\n\ninterface StoreOptions {\n state?: Record<string, unknown> | (() => Record<string, unknown>);\n getters?: Record<string, Function>;\n mutations?: Record<string, Function>;\n actions?: Record<string, Function>;\n}\n\ninterface StoreInstance {\n // eslint-disable-next-line no-unused-vars\n new (options: StoreOptions): StoreInstance;\n state: Record<string, any>;\n getters?: Record<string, any>;\n // eslint-disable-next-line no-unused-vars\n commit: (type: string, ...payload: any[]) => void;\n // eslint-disable-next-line no-unused-vars\n dispatch: (type: string, ...payload: any[]) => void;\n}\n\nfunction keyExists(typeOfKey: string, object: Record<string, unknown>, key: string) {\n if (key in object === false) {\n throw new Error(`The ${typeOfKey} \"${key}\" does not exists.`);\n }\n}\n\nfunction deepFreeze(obj: any) {\n if (typeof obj === \"object\" && obj !== null && !Object.isFrozen(obj)) {\n if (Array.isArray(obj)) {\n for (let i = 0, l = obj.length; i < l; i++) {\n deepFreeze(obj[i]);\n }\n } else {\n let props = Reflect.ownKeys(obj);\n for (let i = 0, l = props.length; i < l; i++) {\n deepFreeze(obj[props[i]]);\n }\n }\n Object.freeze(obj);\n }\n\n return obj;\n}\n\nlet updateTimeout: any;\nfunction delayedUpdate() {\n clearTimeout(updateTimeout);\n updateTimeout = setTimeout(update);\n}\n\nexport const Store = function Store(\n this: StoreInstance,\n { state = {}, getters = {}, actions = {}, mutations = {} }: StoreOptions = {}\n) {\n let frozen = true;\n\n function isUnfrozen() {\n if (frozen) {\n throw new Error(\"You need to commit a mutation to change the state\");\n }\n }\n\n let localState = typeof state === \"function\" ? state() : state;\n\n this.state = new Proxy(localState || {}, {\n get: (state, prop: string) => deepFreeze(state[prop]),\n set: (state, prop: string, value: any) => {\n isUnfrozen();\n state[prop] = value;\n return true;\n },\n deleteProperty: (state, prop: string) => {\n isUnfrozen();\n Reflect.deleteProperty(state, prop);\n return true;\n }\n });\n\n this.getters = new Proxy(getters, {\n get: (getters, getter: string) => {\n try {\n return getters[getter](this.state, this.getters);\n } catch (e) {\n // Getters should fail silently\n }\n }\n });\n\n this.commit = (mutation, ...args) => {\n keyExists(\"mutation\", mutations, mutation);\n frozen = false;\n mutations[mutation](this.state, ...args);\n frozen = true;\n delayedUpdate();\n };\n\n this.dispatch = (action, ...args) => {\n keyExists(\"action\", actions, action);\n return Promise.resolve(actions[action](this, ...args));\n };\n} as unknown as StoreInstance;\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAuB;AAoBvB,SAAS,UAAU,WAAmB,QAAiC,KAAa;AAClF,MAAI,OAAO,WAAW,OAAO;AAC3B,UAAM,IAAI,MAAM,OAAO,SAAS,KAAK,GAAG,oBAAoB;AAAA,EAC9D;AACF;AAEA,SAAS,WAAW,KAAU;AAC5B,MAAI,OAAO,QAAQ,YAAY,QAAQ,QAAQ,CAAC,OAAO,SAAS,GAAG,GAAG;AACpE,QAAI,MAAM,QAAQ,GAAG,GAAG;AACtB,eAAS,IAAI,GAAG,IAAI,IAAI,QAAQ,IAAI,GAAG,KAAK;AAC1C,mBAAW,IAAI,CAAC,CAAC;AAAA,MACnB;AAAA,IACF,OAAO;AACL,UAAI,QAAQ,QAAQ,QAAQ,GAAG;AAC/B,eAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,IAAI,GAAG,KAAK;AAC5C,mBAAW,IAAI,MAAM,CAAC,CAAC,CAAC;AAAA,MAC1B;AAAA,IACF;AACA,WAAO,OAAO,GAAG;AAAA,EACnB;AAEA,SAAO;AACT;AAEA,IAAI;AACJ,SAAS,gBAAgB;AACvB,eAAa,aAAa;AAC1B,kBAAgB,WAAW,sBAAM;AACnC;AAEO,IAAM,QAAQ,SAASA,OAE5B,EAAE,QAAQ,CAAC,GAAG,UAAU,CAAC,GAAG,UAAU,CAAC,GAAG,YAAY,CAAC,EAAE,IAAkB,CAAC,GAC5E;AACA,MAAI,SAAS;AAEb,WAAS,aAAa;AACpB,QAAI,QAAQ;AACV,YAAM,IAAI,MAAM,mDAAmD;AAAA,IACrE;AAAA,EACF;AAEA,MAAI,aAAa,OAAO,UAAU,aAAa,MAAM,IAAI;AAEzD,OAAK,QAAQ,IAAI,MAAM,cAAc,CAAC,GAAG;AAAA,IACvC,KAAK,CAACC,QAAO,SAAiB,WAAWA,OAAM,IAAI,CAAC;AAAA,IACpD,KAAK,CAACA,QAAO,MAAc,UAAe;AACxC,iBAAW;AACX,MAAAA,OAAM,IAAI,IAAI;AACd,aAAO;AAAA,IACT;AAAA,IACA,gBAAgB,CAACA,QAAO,SAAiB;AACvC,iBAAW;AACX,cAAQ,eAAeA,QAAO,IAAI;AAClC,aAAO;AAAA,IACT;AAAA,EACF,CAAC;AAED,OAAK,UAAU,IAAI,MAAM,SAAS;AAAA,IAChC,KAAK,CAACC,UAAS,WAAmB;AAChC,UAAI;AACF,eAAOA,SAAQ,MAAM,EAAE,KAAK,OAAO,KAAK,OAAO;AAAA,MACjD,SAAS,GAAG;AAAA,MAEZ;AAAA,IACF;AAAA,EACF,CAAC;AAED,OAAK,SAAS,CAAC,aAAa,SAAS;AACnC,cAAU,YAAY,WAAW,QAAQ;AACzC,aAAS;AACT,cAAU,QAAQ,EAAE,KAAK,OAAO,GAAG,IAAI;AACvC,aAAS;AACT,kBAAc;AAAA,EAChB;AAEA,OAAK,WAAW,CAAC,WAAW,SAAS;AACnC,cAAU,UAAU,SAAS,MAAM;AACnC,WAAO,QAAQ,QAAQ,QAAQ,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;AAAA,EACvD;AACF;",
|
|
6
|
-
"names": ["Store", "state", "getters"]
|
|
7
|
-
}
|
package/dist/store/index.mjs
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
// lib/store/index.ts
|
|
2
|
-
import { update } from "valyrian.js";
|
|
3
|
-
function keyExists(typeOfKey, object, key) {
|
|
4
|
-
if (key in object === false) {
|
|
5
|
-
throw new Error(`The ${typeOfKey} "${key}" does not exists.`);
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
function deepFreeze(obj) {
|
|
9
|
-
if (typeof obj === "object" && obj !== null && !Object.isFrozen(obj)) {
|
|
10
|
-
if (Array.isArray(obj)) {
|
|
11
|
-
for (let i = 0, l = obj.length; i < l; i++) {
|
|
12
|
-
deepFreeze(obj[i]);
|
|
13
|
-
}
|
|
14
|
-
} else {
|
|
15
|
-
let props = Reflect.ownKeys(obj);
|
|
16
|
-
for (let i = 0, l = props.length; i < l; i++) {
|
|
17
|
-
deepFreeze(obj[props[i]]);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
Object.freeze(obj);
|
|
21
|
-
}
|
|
22
|
-
return obj;
|
|
23
|
-
}
|
|
24
|
-
var updateTimeout;
|
|
25
|
-
function delayedUpdate() {
|
|
26
|
-
clearTimeout(updateTimeout);
|
|
27
|
-
updateTimeout = setTimeout(update);
|
|
28
|
-
}
|
|
29
|
-
var Store = function Store2({ state = {}, getters = {}, actions = {}, mutations = {} } = {}) {
|
|
30
|
-
let frozen = true;
|
|
31
|
-
function isUnfrozen() {
|
|
32
|
-
if (frozen) {
|
|
33
|
-
throw new Error("You need to commit a mutation to change the state");
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
let localState = typeof state === "function" ? state() : state;
|
|
37
|
-
this.state = new Proxy(localState || {}, {
|
|
38
|
-
get: (state2, prop) => deepFreeze(state2[prop]),
|
|
39
|
-
set: (state2, prop, value) => {
|
|
40
|
-
isUnfrozen();
|
|
41
|
-
state2[prop] = value;
|
|
42
|
-
return true;
|
|
43
|
-
},
|
|
44
|
-
deleteProperty: (state2, prop) => {
|
|
45
|
-
isUnfrozen();
|
|
46
|
-
Reflect.deleteProperty(state2, prop);
|
|
47
|
-
return true;
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
this.getters = new Proxy(getters, {
|
|
51
|
-
get: (getters2, getter) => {
|
|
52
|
-
try {
|
|
53
|
-
return getters2[getter](this.state, this.getters);
|
|
54
|
-
} catch (e) {
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
this.commit = (mutation, ...args) => {
|
|
59
|
-
keyExists("mutation", mutations, mutation);
|
|
60
|
-
frozen = false;
|
|
61
|
-
mutations[mutation](this.state, ...args);
|
|
62
|
-
frozen = true;
|
|
63
|
-
delayedUpdate();
|
|
64
|
-
};
|
|
65
|
-
this.dispatch = (action, ...args) => {
|
|
66
|
-
keyExists("action", actions, action);
|
|
67
|
-
return Promise.resolve(actions[action](this, ...args));
|
|
68
|
-
};
|
|
69
|
-
};
|
|
70
|
-
export {
|
|
71
|
-
Store
|
|
72
|
-
};
|
package/dist/store/index.mjs.map
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../lib/store/index.ts"],
|
|
4
|
-
"sourcesContent": ["import { update } from \"valyrian.js\";\n\ninterface StoreOptions {\n state?: Record<string, unknown> | (() => Record<string, unknown>);\n getters?: Record<string, Function>;\n mutations?: Record<string, Function>;\n actions?: Record<string, Function>;\n}\n\ninterface StoreInstance {\n // eslint-disable-next-line no-unused-vars\n new (options: StoreOptions): StoreInstance;\n state: Record<string, any>;\n getters?: Record<string, any>;\n // eslint-disable-next-line no-unused-vars\n commit: (type: string, ...payload: any[]) => void;\n // eslint-disable-next-line no-unused-vars\n dispatch: (type: string, ...payload: any[]) => void;\n}\n\nfunction keyExists(typeOfKey: string, object: Record<string, unknown>, key: string) {\n if (key in object === false) {\n throw new Error(`The ${typeOfKey} \"${key}\" does not exists.`);\n }\n}\n\nfunction deepFreeze(obj: any) {\n if (typeof obj === \"object\" && obj !== null && !Object.isFrozen(obj)) {\n if (Array.isArray(obj)) {\n for (let i = 0, l = obj.length; i < l; i++) {\n deepFreeze(obj[i]);\n }\n } else {\n let props = Reflect.ownKeys(obj);\n for (let i = 0, l = props.length; i < l; i++) {\n deepFreeze(obj[props[i]]);\n }\n }\n Object.freeze(obj);\n }\n\n return obj;\n}\n\nlet updateTimeout: any;\nfunction delayedUpdate() {\n clearTimeout(updateTimeout);\n updateTimeout = setTimeout(update);\n}\n\nexport const Store = function Store(\n this: StoreInstance,\n { state = {}, getters = {}, actions = {}, mutations = {} }: StoreOptions = {}\n) {\n let frozen = true;\n\n function isUnfrozen() {\n if (frozen) {\n throw new Error(\"You need to commit a mutation to change the state\");\n }\n }\n\n let localState = typeof state === \"function\" ? state() : state;\n\n this.state = new Proxy(localState || {}, {\n get: (state, prop: string) => deepFreeze(state[prop]),\n set: (state, prop: string, value: any) => {\n isUnfrozen();\n state[prop] = value;\n return true;\n },\n deleteProperty: (state, prop: string) => {\n isUnfrozen();\n Reflect.deleteProperty(state, prop);\n return true;\n }\n });\n\n this.getters = new Proxy(getters, {\n get: (getters, getter: string) => {\n try {\n return getters[getter](this.state, this.getters);\n } catch (e) {\n // Getters should fail silently\n }\n }\n });\n\n this.commit = (mutation, ...args) => {\n keyExists(\"mutation\", mutations, mutation);\n frozen = false;\n mutations[mutation](this.state, ...args);\n frozen = true;\n delayedUpdate();\n };\n\n this.dispatch = (action, ...args) => {\n keyExists(\"action\", actions, action);\n return Promise.resolve(actions[action](this, ...args));\n };\n} as unknown as StoreInstance;\n"],
|
|
5
|
-
"mappings": ";AAAA,SAAS,cAAc;AAoBvB,SAAS,UAAU,WAAmB,QAAiC,KAAa;AAClF,MAAI,OAAO,WAAW,OAAO;AAC3B,UAAM,IAAI,MAAM,OAAO,SAAS,KAAK,GAAG,oBAAoB;AAAA,EAC9D;AACF;AAEA,SAAS,WAAW,KAAU;AAC5B,MAAI,OAAO,QAAQ,YAAY,QAAQ,QAAQ,CAAC,OAAO,SAAS,GAAG,GAAG;AACpE,QAAI,MAAM,QAAQ,GAAG,GAAG;AACtB,eAAS,IAAI,GAAG,IAAI,IAAI,QAAQ,IAAI,GAAG,KAAK;AAC1C,mBAAW,IAAI,CAAC,CAAC;AAAA,MACnB;AAAA,IACF,OAAO;AACL,UAAI,QAAQ,QAAQ,QAAQ,GAAG;AAC/B,eAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,IAAI,GAAG,KAAK;AAC5C,mBAAW,IAAI,MAAM,CAAC,CAAC,CAAC;AAAA,MAC1B;AAAA,IACF;AACA,WAAO,OAAO,GAAG;AAAA,EACnB;AAEA,SAAO;AACT;AAEA,IAAI;AACJ,SAAS,gBAAgB;AACvB,eAAa,aAAa;AAC1B,kBAAgB,WAAW,MAAM;AACnC;AAEO,IAAM,QAAQ,SAASA,OAE5B,EAAE,QAAQ,CAAC,GAAG,UAAU,CAAC,GAAG,UAAU,CAAC,GAAG,YAAY,CAAC,EAAE,IAAkB,CAAC,GAC5E;AACA,MAAI,SAAS;AAEb,WAAS,aAAa;AACpB,QAAI,QAAQ;AACV,YAAM,IAAI,MAAM,mDAAmD;AAAA,IACrE;AAAA,EACF;AAEA,MAAI,aAAa,OAAO,UAAU,aAAa,MAAM,IAAI;AAEzD,OAAK,QAAQ,IAAI,MAAM,cAAc,CAAC,GAAG;AAAA,IACvC,KAAK,CAACC,QAAO,SAAiB,WAAWA,OAAM,IAAI,CAAC;AAAA,IACpD,KAAK,CAACA,QAAO,MAAc,UAAe;AACxC,iBAAW;AACX,MAAAA,OAAM,IAAI,IAAI;AACd,aAAO;AAAA,IACT;AAAA,IACA,gBAAgB,CAACA,QAAO,SAAiB;AACvC,iBAAW;AACX,cAAQ,eAAeA,QAAO,IAAI;AAClC,aAAO;AAAA,IACT;AAAA,EACF,CAAC;AAED,OAAK,UAAU,IAAI,MAAM,SAAS;AAAA,IAChC,KAAK,CAACC,UAAS,WAAmB;AAChC,UAAI;AACF,eAAOA,SAAQ,MAAM,EAAE,KAAK,OAAO,KAAK,OAAO;AAAA,MACjD,SAAS,GAAG;AAAA,MAEZ;AAAA,IACF;AAAA,EACF,CAAC;AAED,OAAK,SAAS,CAAC,aAAa,SAAS;AACnC,cAAU,YAAY,WAAW,QAAQ;AACzC,aAAS;AACT,cAAU,QAAQ,EAAE,KAAK,OAAO,GAAG,IAAI;AACvC,aAAS;AACT,kBAAc;AAAA,EAChB;AAEA,OAAK,WAAW,CAAC,WAAW,SAAS;AACnC,cAAU,UAAU,SAAS,MAAM;AACnC,WAAO,QAAQ,QAAQ,QAAQ,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;AAAA,EACvD;AACF;",
|
|
6
|
-
"names": ["Store", "state", "getters"]
|
|
7
|
-
}
|
package/lib/dataset/index.ts
DELETED
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
import { VnodeInterface, VnodeWithDom, createDomElement, directive, patch, updateAttributes } from "valyrian.js";
|
|
2
|
-
|
|
3
|
-
interface DataSetInterface<T> {
|
|
4
|
-
data: T[];
|
|
5
|
-
// eslint-disable-next-line no-unused-vars
|
|
6
|
-
reset: (data: T[]) => void;
|
|
7
|
-
// eslint-disable-next-line no-unused-vars
|
|
8
|
-
add: (...data: T[]) => void;
|
|
9
|
-
// eslint-disable-next-line no-unused-vars
|
|
10
|
-
update: (index: number, data: T) => void;
|
|
11
|
-
// eslint-disable-next-line no-unused-vars
|
|
12
|
-
delete: (index: number) => void;
|
|
13
|
-
}
|
|
14
|
-
interface DataSetHandler<T> {
|
|
15
|
-
// eslint-disable-next-line no-unused-vars
|
|
16
|
-
(data: T, index: number): VnodeInterface;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function deepFreeze(obj: any) {
|
|
20
|
-
if (typeof obj === "object" && obj !== null && !Object.isFrozen(obj)) {
|
|
21
|
-
if (Array.isArray(obj)) {
|
|
22
|
-
for (let i = 0, l = obj.length; i < l; i++) {
|
|
23
|
-
deepFreeze(obj[i]);
|
|
24
|
-
}
|
|
25
|
-
} else {
|
|
26
|
-
let props = Reflect.ownKeys(obj);
|
|
27
|
-
for (let i = 0, l = props.length; i < l; i++) {
|
|
28
|
-
deepFreeze(obj[props[i]]);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
Object.freeze(obj);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return obj;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export class DataSet<T> implements DataSetInterface<T> {
|
|
38
|
-
#vnode: VnodeWithDom | null = null;
|
|
39
|
-
// eslint-disable-next-line no-unused-vars
|
|
40
|
-
#handler: DataSetHandler<T> | null = null;
|
|
41
|
-
#data: T[] = [];
|
|
42
|
-
#isFrozen = false;
|
|
43
|
-
#dataProxy: T[] | null = null;
|
|
44
|
-
|
|
45
|
-
get data() {
|
|
46
|
-
if (this.#dataProxy === null) {
|
|
47
|
-
throw new Error("DataSet is not initialized");
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return this.#dataProxy;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
set data(data: T[]) {
|
|
54
|
-
throw new Error("You need to use the reset method to set the data");
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
#setData(data: T[]) {
|
|
58
|
-
if (this.#isFrozen) {
|
|
59
|
-
this.#data = deepFreeze([...data]);
|
|
60
|
-
} else {
|
|
61
|
-
this.#data = data;
|
|
62
|
-
}
|
|
63
|
-
this.#dataProxy = new Proxy(this.#data as T[], {
|
|
64
|
-
set: () => {
|
|
65
|
-
throw new Error("You need to use the add, update or delete methods to change the data");
|
|
66
|
-
},
|
|
67
|
-
get(target: any, prop: string) {
|
|
68
|
-
return target[prop];
|
|
69
|
-
},
|
|
70
|
-
deleteProperty: () => {
|
|
71
|
-
throw new Error("You need to use the add, update or delete methods to change the data");
|
|
72
|
-
}
|
|
73
|
-
}) as T[];
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
constructor(data: T[] = [], shouldFreeze = true) {
|
|
77
|
-
this.#isFrozen = shouldFreeze;
|
|
78
|
-
this.#setData(data);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
setVnodeAndHandler(vnode: VnodeWithDom, handler: DataSetHandler<T>) {
|
|
82
|
-
this.#vnode = vnode;
|
|
83
|
-
this.#handler = handler;
|
|
84
|
-
this.reset(this.#data);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
reset(data: T[]) {
|
|
88
|
-
this.#setData(data);
|
|
89
|
-
if (this.#vnode === null || this.#handler === null) {
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
let vnode = this.#vnode;
|
|
94
|
-
let handler = this.#handler;
|
|
95
|
-
|
|
96
|
-
if (data.length === 0) {
|
|
97
|
-
vnode.children = [];
|
|
98
|
-
vnode.dom.textContent = "";
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
let childrenLength = vnode.children.length;
|
|
103
|
-
for (let i = 0, l = data.length; i < l; i++) {
|
|
104
|
-
let child = handler(this.data[i], i);
|
|
105
|
-
|
|
106
|
-
if (i < childrenLength) {
|
|
107
|
-
let oldChild = vnode.children[i];
|
|
108
|
-
child.isSVG = oldChild.isSVG;
|
|
109
|
-
child.dom = oldChild.dom;
|
|
110
|
-
updateAttributes(child as VnodeWithDom, oldChild);
|
|
111
|
-
vnode.children[i] = child;
|
|
112
|
-
patch(child as VnodeWithDom, oldChild);
|
|
113
|
-
continue;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
child.isSVG = vnode.isSVG || child.tag === "svg";
|
|
117
|
-
child.dom = createDomElement(child.tag as string, child.isSVG);
|
|
118
|
-
vnode.dom.appendChild(child.dom);
|
|
119
|
-
updateAttributes(child as VnodeWithDom);
|
|
120
|
-
vnode.children.push(child);
|
|
121
|
-
patch(child as VnodeWithDom);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
for (let i = data.length; i < childrenLength; i++) {
|
|
125
|
-
vnode.dom.removeChild(vnode.children[i].dom);
|
|
126
|
-
}
|
|
127
|
-
vnode.children.length = data.length;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
add(...data: T[]) {
|
|
131
|
-
if (this.#data) {
|
|
132
|
-
let oldLength = this.#data.length;
|
|
133
|
-
if (this.#isFrozen) {
|
|
134
|
-
this.#setData([...this.#data, ...data]);
|
|
135
|
-
} else {
|
|
136
|
-
this.#data.push(...data);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
if (this.#vnode === null || this.#handler === null) {
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
let vnode = this.#vnode;
|
|
144
|
-
let handler = this.#handler;
|
|
145
|
-
|
|
146
|
-
for (let i = 0, ii = oldLength, l = data.length; i < l; i++, ii++) {
|
|
147
|
-
let child = handler(this.#data[i], ii);
|
|
148
|
-
child.isSVG = vnode.isSVG || child.tag === "svg";
|
|
149
|
-
child.dom = createDomElement(child.tag as string, child.isSVG);
|
|
150
|
-
vnode.dom.appendChild(child.dom);
|
|
151
|
-
updateAttributes(child as VnodeWithDom);
|
|
152
|
-
vnode.children.push(child);
|
|
153
|
-
patch(child as VnodeWithDom);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
delete(index: number) {
|
|
159
|
-
if (this.#data && this.#vnode) {
|
|
160
|
-
let child = this.#vnode.children[index];
|
|
161
|
-
if (this.#isFrozen) {
|
|
162
|
-
this.#setData(this.data.filter((_, i) => i !== index));
|
|
163
|
-
} else {
|
|
164
|
-
this.#data.splice(index, 1);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
this.#vnode.dom.removeChild(child.dom);
|
|
168
|
-
this.#vnode.children.splice(index, 1);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
update(index: number, item: Partial<T>) {
|
|
173
|
-
if (this.#data && this.#vnode && this.#handler) {
|
|
174
|
-
let child = this.#vnode.children[index];
|
|
175
|
-
if (this.#isFrozen) {
|
|
176
|
-
this.#setData(this.#data.map((d, i) => (i === index ? { ...d, ...item } : d)));
|
|
177
|
-
} else {
|
|
178
|
-
this.#data[index] = { ...this.#data[index], ...item };
|
|
179
|
-
}
|
|
180
|
-
let newChild = this.#handler(this.#data[index], index);
|
|
181
|
-
newChild.isSVG = this.#vnode.isSVG || newChild.tag === "svg";
|
|
182
|
-
newChild.dom = child.dom;
|
|
183
|
-
this.#vnode.children[index] = newChild;
|
|
184
|
-
updateAttributes(newChild as VnodeWithDom, child);
|
|
185
|
-
patch(newChild as VnodeWithDom, child);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
directive("with-dataset", (dataSet, vnode) => {
|
|
191
|
-
dataSet.setVnodeAndHandler(vnode as VnodeWithDom, vnode.children[0]);
|
|
192
|
-
return false;
|
|
193
|
-
});
|
package/lib/index.d.ts
DELETED
|
File without changes
|
package/lib/interfaces.ts.bak
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-use-before-define */
|
|
2
|
-
/* eslint-disable no-unused-vars */
|
|
3
|
-
declare module "valyrian.js" {
|
|
4
|
-
interface DefaultRecord extends Record<string | number | symbol, any> {}
|
|
5
|
-
|
|
6
|
-
// The VnodeProperties interface represents properties that can be passed to a virtual node.
|
|
7
|
-
export interface VnodeProperties extends DefaultRecord {
|
|
8
|
-
// A unique key for the virtual node, which can be a string or a number.
|
|
9
|
-
// This is useful for optimizing updates in a list of nodes.
|
|
10
|
-
key?: string | number;
|
|
11
|
-
// A state object that is associated with the virtual node.
|
|
12
|
-
state?: any;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// The DomElement interface extends the Element interface with an index signature.
|
|
16
|
-
// This allows for any additional properties to be added to DOM elements.
|
|
17
|
-
export interface DomElement extends Element, DefaultRecord {}
|
|
18
|
-
|
|
19
|
-
// The VnodeInterface represents a virtual node. It has a number of optional fields,
|
|
20
|
-
// including a tag, props, children, and a DOM element.
|
|
21
|
-
export interface VnodeInterface extends DefaultRecord {
|
|
22
|
-
// The constructor for the virtual node. It takes a tag, props, and children as arguments.
|
|
23
|
-
// The tag can be a string, a component, or a POJO component.
|
|
24
|
-
// eslint-disable-next-line no-unused-vars
|
|
25
|
-
new (tag: string | Component | POJOComponent, props: VnodeProperties, children: Children): VnodeInterface;
|
|
26
|
-
// The tag for the virtual node. It can be a string, a component, or a POJO component.
|
|
27
|
-
tag: string | Component | POJOComponent;
|
|
28
|
-
// The props for the virtual node.
|
|
29
|
-
props: VnodeProperties;
|
|
30
|
-
// The children for the virtual node.
|
|
31
|
-
children: Children;
|
|
32
|
-
// A boolean indicating whether the virtual node is an SVG element.
|
|
33
|
-
isSVG?: boolean;
|
|
34
|
-
// The DOM element that corresponds to the virtual node.
|
|
35
|
-
dom?: DomElement;
|
|
36
|
-
// A boolean indicating whether the virtual node has been processed in the keyed diffing algorithm.
|
|
37
|
-
processed?: boolean;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// The VnodeWithDom interface represents a virtual node that has a DOM element associated with it.
|
|
41
|
-
export interface VnodeWithDom extends VnodeInterface {
|
|
42
|
-
dom: DomElement;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// The Component interface represents a function that returns a virtual node or a list of virtual nodes.
|
|
46
|
-
// It can also have additional properties.
|
|
47
|
-
export interface Component extends DefaultRecord {
|
|
48
|
-
// The function that returns a virtual node or a list of virtual nodes.
|
|
49
|
-
// It can take props and children as arguments.
|
|
50
|
-
// eslint-disable-next-line no-unused-vars
|
|
51
|
-
(props?: VnodeProperties | null, ...children: any[]): VnodeInterface | Children | any;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// The POJOComponent interface represents a "plain old JavaScript object" (POJO) component.
|
|
55
|
-
// It has a view function that returns a virtual node or a list of virtual nodes,
|
|
56
|
-
// as well as optional props and children.
|
|
57
|
-
// It can be used also to identify class instance components.
|
|
58
|
-
export interface POJOComponent extends DefaultRecord {
|
|
59
|
-
// The view function that returns a virtual node or a list of virtual nodes.
|
|
60
|
-
view: Component;
|
|
61
|
-
// The props for the component.
|
|
62
|
-
props?: VnodeProperties | null;
|
|
63
|
-
// The children for the component.
|
|
64
|
-
children?: any[];
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// The VnodeComponentInterface represents a virtual node that has a component as its tag.
|
|
68
|
-
// It has props and children, just like a regular virtual node.
|
|
69
|
-
export interface VnodeComponentInterface extends VnodeInterface {
|
|
70
|
-
tag: Component | POJOComponent;
|
|
71
|
-
props: VnodeProperties;
|
|
72
|
-
children: Children;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// The Children interface represents a list of virtual nodes or other values.
|
|
76
|
-
export interface Children extends Array<VnodeInterface | VnodeComponentInterface | any> {}
|
|
77
|
-
|
|
78
|
-
// The Directive interface represents a function that can be applied to a virtual node.
|
|
79
|
-
// It receives the value, virtual node, and old virtual node as arguments, and can return a boolean value.
|
|
80
|
-
// If only the virtual node is passed, it means its the on create phase for the v-node.
|
|
81
|
-
// If the old virtual node is also passed, it means its the on update phase for the v-node.
|
|
82
|
-
export interface Directive {
|
|
83
|
-
// eslint-disable-next-line no-unused-vars
|
|
84
|
-
(value: any, vnode: VnodeWithDom, oldVnode?: VnodeWithDom): void | boolean;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// The Directives interface is a mapping of directive names to Directive functions.
|
|
88
|
-
export interface Directives extends Record<string, Directive> {}
|
|
89
|
-
|
|
90
|
-
// The ReservedProps interface is a mapping of reserved prop names to the value `true`.
|
|
91
|
-
// These prop names cannot be used as custom prop names.
|
|
92
|
-
export interface ReservedProps extends Record<string, true> {}
|
|
93
|
-
|
|
94
|
-
// The Current interface represents the current component and virtual node that are being processed.
|
|
95
|
-
export interface Current {
|
|
96
|
-
// The current component. It can be a component, a POJO component, or null.
|
|
97
|
-
component: Component | POJOComponent | null;
|
|
98
|
-
// The current virtual node. It must have a DOM element associated with it.
|
|
99
|
-
vnode: VnodeWithDom | null;
|
|
100
|
-
// The old virtual node. It must have a DOM element associated with it.
|
|
101
|
-
oldVnode?: VnodeWithDom | null;
|
|
102
|
-
// The current event. It can be an event or null.
|
|
103
|
-
event: Event | null;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// The V function is the main function for creating virtual nodes.
|
|
107
|
-
// It takes a tag or component, props, and children as arguments, and returns a virtual node.
|
|
108
|
-
export interface V {
|
|
109
|
-
// eslint-disable-next-line no-unused-vars, no-use-before-define
|
|
110
|
-
(tagOrComponent: string | Component | POJOComponent, props: VnodeProperties | null, ...children: Children):
|
|
111
|
-
| VnodeInterface
|
|
112
|
-
| VnodeComponentInterface;
|
|
113
|
-
// eslint-disable-next-line no-unused-vars, no-use-before-define
|
|
114
|
-
fragment(_: any, ...children: Children): Children;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
export let isNodeJs: boolean;
|
|
118
|
-
export function createDomElement(tag: string, isSVG?: boolean): DomElement;
|
|
119
|
-
export const Vnode: VnodeInterface;
|
|
120
|
-
export function isComponent(component: any): component is Component;
|
|
121
|
-
export const isVnode: (object?: unknown | VnodeInterface) => object is VnodeInterface;
|
|
122
|
-
export const isVnodeComponent: (object?: unknown | VnodeComponentInterface) => object is VnodeComponentInterface;
|
|
123
|
-
export function domToVnode(dom: any): VnodeWithDom;
|
|
124
|
-
export function trust(htmlString: string): any;
|
|
125
|
-
export const current: Current;
|
|
126
|
-
export const reservedProps: Record<string, true>;
|
|
127
|
-
export function onMount(callback: any): void;
|
|
128
|
-
export function onUpdate(callback: any): void;
|
|
129
|
-
export function onCleanup(callback: any): void;
|
|
130
|
-
export function onUnmount(callback: any): void;
|
|
131
|
-
export const directives: Directives;
|
|
132
|
-
export function directive(name: string, directive: Directive): void;
|
|
133
|
-
export function setAttribute(name: string, value: any, newVnode: VnodeWithDom, oldVnode?: VnodeWithDom): void;
|
|
134
|
-
export function updateAttributes(newVnode: VnodeWithDom, oldVnode?: VnodeWithDom): void;
|
|
135
|
-
export function patch(newVnode: VnodeWithDom, oldVnode?: VnodeWithDom): void;
|
|
136
|
-
export function update(): void | string;
|
|
137
|
-
export function updateVnode(vnode: VnodeWithDom, oldVnode: VnodeWithDom): string | void;
|
|
138
|
-
export function unmount(): string | void;
|
|
139
|
-
export function mount(dom: any, component: any): string | void;
|
|
140
|
-
export const v: V;
|
|
141
|
-
}
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
let Log = console.log;
|
|
2
|
-
|
|
3
|
-
let config = {
|
|
4
|
-
version: "v1::",
|
|
5
|
-
name: "Valyrian.js",
|
|
6
|
-
urls: ["/"]
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
let cacheName = config.version + config.name;
|
|
10
|
-
|
|
11
|
-
async function fetchRequest(event) {
|
|
12
|
-
Log("WORKER: fetchevent for " + event.request.url);
|
|
13
|
-
let response;
|
|
14
|
-
try {
|
|
15
|
-
// IMPORTANT: Clone the request. A request is a stream and
|
|
16
|
-
// can only be consumed once. Since we are consuming this
|
|
17
|
-
// once by cache and once by the browser for fetch, we need
|
|
18
|
-
// to clone the response.
|
|
19
|
-
let fetchRequest = event.request.clone();
|
|
20
|
-
response = await fetch(fetchRequest);
|
|
21
|
-
if (response && response.status < 300 && response.type === "basic") {
|
|
22
|
-
try {
|
|
23
|
-
// IMPORTANT: Clone the response. A response is a stream
|
|
24
|
-
// and because we want the browser to consume the response
|
|
25
|
-
// as well as the cache consuming the response, we need
|
|
26
|
-
// to clone it so we have two streams.
|
|
27
|
-
let responseToCache = response.clone();
|
|
28
|
-
let cache = await caches.open(cacheName);
|
|
29
|
-
cache.put(event.request, responseToCache);
|
|
30
|
-
|
|
31
|
-
Log("WORKER: fetch response stored in cache.", event.request.url);
|
|
32
|
-
} catch (err) {
|
|
33
|
-
Log("WORKER: fetch response could not be stored in cache.", err);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return response;
|
|
37
|
-
}
|
|
38
|
-
} catch (error) {
|
|
39
|
-
Log("WORKER: fetch request failed.", error);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
let cachedResponse;
|
|
43
|
-
try {
|
|
44
|
-
cachedResponse = await caches.match(event.request);
|
|
45
|
-
if (cachedResponse) {
|
|
46
|
-
Log("WORKER: fetch request failed, responding with cache.");
|
|
47
|
-
return cachedResponse;
|
|
48
|
-
}
|
|
49
|
-
} catch (error) {
|
|
50
|
-
Log("WORKER: cache request failed.", error);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
Log(
|
|
54
|
-
"WORKER: fetch request failed in both cache and network, responding with service unavailable."
|
|
55
|
-
);
|
|
56
|
-
return (
|
|
57
|
-
response ||
|
|
58
|
-
new Response("<h1>Service Unavailable</h1>", {
|
|
59
|
-
status: 503,
|
|
60
|
-
statusText: "Service Unavailable",
|
|
61
|
-
headers: new Headers({
|
|
62
|
-
"Content-Type": "text/html"
|
|
63
|
-
})
|
|
64
|
-
})
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
self.addEventListener("fetch", (event) => {
|
|
69
|
-
// DevTools opening will trigger these o-i-c requests, which this SW can't handle.
|
|
70
|
-
// https://github.com/paulirish/caltrainschedule.io/issues/49
|
|
71
|
-
if (
|
|
72
|
-
event.request.cache === "only-if-cached" &&
|
|
73
|
-
event.request.mode !== "same-origin"
|
|
74
|
-
) {
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
Log("WORKER: fetch event in progress.", event.request.url);
|
|
79
|
-
|
|
80
|
-
// We only handle Get requests all others let them pass
|
|
81
|
-
if (event.request.method !== "GET") {
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
event.respondWith(fetchRequest(event));
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
self.addEventListener("install", (event) => {
|
|
89
|
-
Log("WORKER: Version install", cacheName);
|
|
90
|
-
event.waitUntil(
|
|
91
|
-
caches
|
|
92
|
-
.open(cacheName)
|
|
93
|
-
.then((cache) => cache.addAll(config.urls))
|
|
94
|
-
// IMPORTANT: `skipWaiting()` forces the waiting ServiceWorker to become the
|
|
95
|
-
// active ServiceWorker, triggering the `onactivate` event.
|
|
96
|
-
// Together with `Clients.claim()` this allows a worker to take effect
|
|
97
|
-
// immediately in the client(s).
|
|
98
|
-
.then(() => self.skipWaiting())
|
|
99
|
-
);
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
// IMPORTANT: `onactivate` is usually called after a worker was installed and the page
|
|
103
|
-
// got refreshed. Since we call `skipWaiting()` in `oninstall`, `onactivate` is
|
|
104
|
-
// called immediately.
|
|
105
|
-
self.addEventListener("activate", (event) => {
|
|
106
|
-
self.clients
|
|
107
|
-
.matchAll({
|
|
108
|
-
includeUncontrolled: true
|
|
109
|
-
})
|
|
110
|
-
.then((clientList) => {
|
|
111
|
-
urls = clientList.map((client) => client.url);
|
|
112
|
-
Log("WORKER: Matching clients:", urls.join(", "));
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
event.waitUntil(
|
|
116
|
-
caches
|
|
117
|
-
.keys()
|
|
118
|
-
.then((keys) =>
|
|
119
|
-
Promise.all(
|
|
120
|
-
keys
|
|
121
|
-
// Filter by keys that don't start with the latest version prefix.
|
|
122
|
-
.filter((key) => !key.startsWith(cacheName))
|
|
123
|
-
// Return a promise that's fulfilled when each outdated cache is deleted.
|
|
124
|
-
.map((key) => caches.delete(key))
|
|
125
|
-
)
|
|
126
|
-
)
|
|
127
|
-
|
|
128
|
-
// IMPORTANT: `claim()` sets this worker as the active worker for all clients that
|
|
129
|
-
// match the workers scope and triggers an `oncontrollerchange` event for
|
|
130
|
-
// the clients.
|
|
131
|
-
.then(() => self.clients.claim())
|
|
132
|
-
);
|
|
133
|
-
});
|