Skip to content

Commit 8c61af6

Browse files
committed
some progress
1 parent 3a7ec65 commit 8c61af6

File tree

1 file changed

+21
-9
lines changed
  • packages/svelte/src/internal/client

1 file changed

+21
-9
lines changed

packages/svelte/src/internal/client/proxy.js

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,22 @@ export function proxy(value, prev) {
4646
var stack = DEV && tracing_mode_flag ? get_stack('CreatedAt') : null;
4747
var reaction = active_reaction;
4848

49-
/** @param {any} value */
50-
var child_source = (value) => {
49+
/**
50+
* @param {any} value
51+
* @param {Error | null | undefined} stack
52+
*/
53+
var child_source = (value, stack) => {
5154
var previous_reaction = active_reaction;
5255
set_active_reaction(reaction);
5356
var s = source(value, stack);
5457
set_active_reaction(previous_reaction);
5558
return s;
5659
};
5760

58-
/** @param {() => void} fn */
61+
/**
62+
* @template T
63+
* @param {() => T} fn
64+
*/
5965
var with_parent = (fn) => {
6066
var previous_reaction = active_reaction;
6167
set_active_reaction(reaction);
@@ -116,7 +122,7 @@ export function proxy(value, prev) {
116122
var s = sources.get(prop);
117123

118124
if (s === undefined) {
119-
s = child_source(descriptor.value);
125+
s = with_parent(() => source(descriptor.value, stack));
120126
sources.set(prop, s);
121127
} else {
122128
set(
@@ -133,7 +139,10 @@ export function proxy(value, prev) {
133139

134140
if (s === undefined) {
135141
if (prop in target) {
136-
sources.set(prop, child_source(UNINITIALIZED));
142+
sources.set(
143+
prop,
144+
with_parent(() => source(UNINITIALIZED, stack))
145+
);
137146
}
138147
} else {
139148
// When working with arrays, we need to also ensure we update the length when removing
@@ -167,7 +176,10 @@ export function proxy(value, prev) {
167176

168177
// create a source, but only if it's an own property and not a prototype property
169178
if (s === undefined && (!exists || get_descriptor(target, prop)?.writable)) {
170-
s = child_source(with_parent(() => proxy(exists ? target[prop] : UNINITIALIZED)));
179+
s = child_source(
180+
with_parent(() => proxy(exists ? target[prop] : UNINITIALIZED)),
181+
stack
182+
);
171183
sources.set(prop, s);
172184
}
173185

@@ -235,7 +247,7 @@ export function proxy(value, prev) {
235247
(active_effect !== null && (!has || get_descriptor(target, prop)?.writable))
236248
) {
237249
if (s === undefined) {
238-
s = child_source(has ? with_parent(() => proxy(target[prop])) : UNINITIALIZED);
250+
s = child_source(has ? with_parent(() => proxy(target[prop])) : UNINITIALIZED, stack);
239251
sources.set(prop, s);
240252
}
241253

@@ -262,7 +274,7 @@ export function proxy(value, prev) {
262274
// If the item exists in the original, we need to create a uninitialized source,
263275
// else a later read of the property would result in a source being created with
264276
// the value of the original item at that index.
265-
other_s = child_source(UNINITIALIZED);
277+
other_s = with_parent(() => source(UNINITIALIZED, stack));
266278
sources.set(i + '', other_s);
267279
}
268280
}
@@ -274,7 +286,7 @@ export function proxy(value, prev) {
274286
// object property before writing to that property.
275287
if (s === undefined) {
276288
if (!has || get_descriptor(target, prop)?.writable) {
277-
s = child_source(undefined);
289+
s = child_source(undefined, stack);
278290
set(
279291
s,
280292
with_parent(() => proxy(value))

0 commit comments

Comments
 (0)