@@ -71,50 +71,37 @@ class Svelte4Component {
71
71
*/
72
72
constructor ( options ) {
73
73
var sources = new Map ( ) ;
74
- var add_source = ( /** @type {string | symbol } */ key ) => {
75
- var s = mutable_source ( 0 ) ;
74
+
75
+ /**
76
+ * @param {string | symbol } key
77
+ * @param {unknown } value
78
+ */
79
+ var add_source = ( key , value ) => {
80
+ var s = mutable_source ( value ) ;
76
81
sources . set ( key , s ) ;
77
82
return s ;
78
83
} ;
84
+
79
85
// Replicate coarse-grained props through a proxy that has a version source for
80
86
// each property, which is increment on updates to the property itself. Do not
81
87
// use our $state proxy because that one has fine-grained reactivity.
82
88
const props = new Proxy (
83
89
{ ...( options . props || { } ) , $$events : { } } ,
84
90
{
85
- get ( target , prop , receiver ) {
86
- var value = Reflect . get ( target , prop , receiver ) ;
87
- var s = sources . get ( prop ) ;
88
- if ( s === undefined ) {
89
- s = add_source ( prop ) ;
90
- }
91
- get ( s ) ;
92
- return value ;
91
+ get ( target , prop ) {
92
+ return get ( sources . get ( prop ) ?? add_source ( prop , Reflect . get ( target , prop ) ) ) ;
93
93
} ,
94
94
has ( target , prop ) {
95
- var value = Reflect . has ( target , prop ) ;
96
- var s = sources . get ( prop ) ;
97
- if ( s !== undefined ) {
98
- get ( s ) ;
99
- }
100
- return value ;
95
+ get ( sources . get ( prop ) ?? add_source ( prop , Reflect . get ( target , prop ) ) ) ;
96
+ return Reflect . has ( target , prop ) ;
101
97
} ,
102
98
set ( target , prop , value ) {
103
- var s = sources . get ( prop ) ;
104
- // @ts -ignore
105
- var prev_value = target [ prop ] ;
106
- if ( s === undefined ) {
107
- s = add_source ( prop ) ;
108
- } else if ( safe_not_equal ( prev_value , value ) ) {
109
- // Increment version
110
- set ( s , s . v + 1 ) ;
111
- }
112
- // @ts -ignore
113
- target [ prop ] = value ;
114
- return true ;
99
+ set ( sources . get ( prop ) ?? add_source ( prop , value ) , value ) ;
100
+ return Reflect . set ( target , prop , value ) ;
115
101
}
116
102
}
117
103
) ;
104
+
118
105
this . #instance = ( options . hydrate ? hydrate : mount ) ( options . component , {
119
106
target : options . target ,
120
107
props,
@@ -142,6 +129,7 @@ class Svelte4Component {
142
129
this . #instance. $set = /** @param {Record<string, any> } next */ ( next ) => {
143
130
Object . assign ( props , next ) ;
144
131
} ;
132
+
145
133
this . #instance. $destroy = ( ) => {
146
134
unmount ( this . #instance) ;
147
135
} ;
0 commit comments