pawajs 2.3.1 → 2.3.3

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 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
- useInsert({count})
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>
@@ -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
- snapshot[key] = structuredClone(raw)
21
- } catch {
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 JSON.stringify(a) === JSON.stringify(b)
55
+ return a === b
32
56
  } catch {
33
57
  return false
34
58
  }
@@ -57,7 +81,6 @@ function restorePawaStateFromContext(oldCtx, newCtx,stateContext,oldStateContext
57
81
  newVal.value = oldVal.value
58
82
  }
59
83
  }
60
- stateContext._hmrinitial = freshInitials
61
84
  }
62
85
  export const normal_component=(el,stateContext,setStateContext,mapsPlugin,formerStateContext,pawaContext,stateWatch,hmrPreserverContext,hmrOldStateContext)=>{
63
86
  // Checks if the content is an SVG fragment (graphic elements) without a root <svg> tag.
@@ -337,8 +360,9 @@ export const normal_component=(el,stateContext,setStateContext,mapsPlugin,former
337
360
  stateContexts?._error?.forEach((error) => {
338
361
  throw Error(error)
339
362
  })
340
-
341
- snapShotInsert(component._insert)
363
+ if (__pawaDev.tool) {
364
+ stateContexts._hmrinitial= snapshotInsert(component._insert)
365
+ }
342
366
  render(child, context)
343
367
  }
344
368
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pawajs",
3
- "version": "2.3.1",
3
+ "version": "2.3.3",
4
4
  "type":"module",
5
5
  "description": "pawajs library (reactive web runtime) for easily building web ui, enhancing html element, micro frontend, spa etc ",
6
6
  "main": "index.js",