pawajs 2.3.0 → 2.3.2
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/cdn/index.js +2 -1
- package/normal/component.js +32 -7
- package/package.json +1 -1
package/cdn/index.js
CHANGED
|
@@ -2,7 +2,8 @@ import { $state, html, useInsert, RegisterComponent, pawaStartApp } from "../ind
|
|
|
2
2
|
|
|
3
3
|
export const Counter=()=>{
|
|
4
4
|
const count=$state(0)
|
|
5
|
-
|
|
5
|
+
const data=$state({data:undefined,user:true})
|
|
6
|
+
useInsert({count,data,increment:[{increase:()=>count.value++,step:1}]})
|
|
6
7
|
return html`
|
|
7
8
|
<div>
|
|
8
9
|
<h1>Counter APPs</h1>
|
package/normal/component.js
CHANGED
|
@@ -10,25 +10,49 @@ function isPawaState(obj) {
|
|
|
10
10
|
typeof obj.id === 'string'
|
|
11
11
|
)
|
|
12
12
|
}
|
|
13
|
-
|
|
14
13
|
function snapshotInsert(ctx) {
|
|
15
14
|
const snapshot = {}
|
|
15
|
+
|
|
16
16
|
for (const key of Object.keys(ctx)) {
|
|
17
17
|
const val = ctx[key]
|
|
18
18
|
const raw = isPawaState(val) ? val.value : val
|
|
19
|
+
|
|
20
|
+
if (typeof raw === 'number' || typeof raw === 'string' || typeof raw === 'boolean') {
|
|
21
|
+
snapshot[key] = raw
|
|
22
|
+
continue
|
|
23
|
+
}
|
|
24
|
+
if (raw === null || raw === undefined) {
|
|
25
|
+
snapshot[key] = raw
|
|
26
|
+
continue
|
|
27
|
+
}
|
|
28
|
+
if (typeof raw !== 'object') {
|
|
29
|
+
// function, symbol, bigint
|
|
30
|
+
snapshot[key] = undefined
|
|
31
|
+
continue
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
let lossy = false
|
|
19
35
|
try {
|
|
20
|
-
|
|
21
|
-
|
|
36
|
+
const json = JSON.stringify(raw, (_k, v) => {
|
|
37
|
+
if (typeof v === 'function' || typeof v === 'symbol') {
|
|
38
|
+
lossy = true
|
|
39
|
+
}
|
|
40
|
+
return v
|
|
41
|
+
})
|
|
42
|
+
snapshot[key] = lossy ? undefined : json
|
|
43
|
+
} catch (error) {
|
|
22
44
|
snapshot[key] = undefined
|
|
23
45
|
}
|
|
24
46
|
}
|
|
47
|
+
// console.log(snapshot);
|
|
48
|
+
|
|
25
49
|
return snapshot
|
|
26
50
|
}
|
|
27
51
|
|
|
28
52
|
function sameInitial(a, b) {
|
|
29
53
|
if (a === undefined || b === undefined) return false
|
|
30
54
|
try {
|
|
31
|
-
return
|
|
55
|
+
return a === b
|
|
32
56
|
} catch {
|
|
33
57
|
return false
|
|
34
58
|
}
|
|
@@ -57,7 +81,7 @@ function restorePawaStateFromContext(oldCtx, newCtx,stateContext,oldStateContext
|
|
|
57
81
|
newVal.value = oldVal.value
|
|
58
82
|
}
|
|
59
83
|
}
|
|
60
|
-
stateContext.
|
|
84
|
+
stateContext._hmrinitial = freshInitials
|
|
61
85
|
}
|
|
62
86
|
export const normal_component=(el,stateContext,setStateContext,mapsPlugin,formerStateContext,pawaContext,stateWatch,hmrPreserverContext,hmrOldStateContext)=>{
|
|
63
87
|
// Checks if the content is an SVG fragment (graphic elements) without a root <svg> tag.
|
|
@@ -337,8 +361,9 @@ export const normal_component=(el,stateContext,setStateContext,mapsPlugin,former
|
|
|
337
361
|
stateContexts?._error?.forEach((error) => {
|
|
338
362
|
throw Error(error)
|
|
339
363
|
})
|
|
340
|
-
|
|
341
|
-
|
|
364
|
+
if (hmr) {
|
|
365
|
+
stateContexts._hmrinitial= snapshotInsert(component._insert)
|
|
366
|
+
}
|
|
342
367
|
render(child, context)
|
|
343
368
|
}
|
|
344
369
|
}
|
package/package.json
CHANGED