Skip to content

Commit 6dd301d

Browse files
committed
tidy up
1 parent 9dc3205 commit 6dd301d

File tree

4 files changed

+12
-40
lines changed

4 files changed

+12
-40
lines changed

packages/svelte/src/internal/client/dev/ownership.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/** @typedef {{ file: string, line: number, column: number }} Location */
22

33
import { STATE_SYMBOL } from '../proxy.js';
4-
import { current_component_context, current_owners, deep_read, untrack } from '../runtime.js';
4+
import { untrack } from '../runtime.js';
55

66
/** @type {Record<string, Array<{ start: Location, end: Location, component: Function }>>} */
77
const boundaries = {};
@@ -80,9 +80,6 @@ export function mark_module_end() {
8080
}
8181
}
8282

83-
/** @type {Function | null} */
84-
let new_owner = null;
85-
8683
/**
8784
*
8885
* @param {any} object
@@ -99,8 +96,8 @@ export function add_owner(object, owner) {
9996
* @param {Function} owner
10097
*/
10198
function add_owner_to_object(object, owner) {
102-
if (object?.[STATE_SYMBOL]?.owners && !object[STATE_SYMBOL].owners.has(owner)) {
103-
object[STATE_SYMBOL].owners.add(owner);
99+
if (object?.[STATE_SYMBOL]?.o && !object[STATE_SYMBOL].o.has(owner)) {
100+
object[STATE_SYMBOL].o.add(owner);
104101

105102
for (const key in object) {
106103
add_owner_to_object(object[key], owner);

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

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import {
99
UNINITIALIZED,
1010
mutable_source,
1111
batch_inspect,
12-
set_current_owners,
13-
current_owners,
1412
current_component_context
1513
} from './runtime.js';
1614
import {
@@ -65,7 +63,7 @@ export function proxy(value, immutable = true, owners) {
6563

6664
if (DEV) {
6765
// @ts-expect-error
68-
value[STATE_SYMBOL].owners =
66+
value[STATE_SYMBOL].o =
6967
owners === undefined
7068
? current_component_context
7169
? // @ts-expect-error
@@ -145,7 +143,7 @@ const state_proxy_handler = {
145143
const metadata = target[STATE_SYMBOL];
146144

147145
const s = metadata.s.get(prop);
148-
if (s !== undefined) set(s, proxy(descriptor.value, metadata.i, metadata.owners));
146+
if (s !== undefined) set(s, proxy(descriptor.value, metadata.i, metadata.o));
149147
}
150148

151149
return Reflect.defineProperty(target, prop, descriptor);
@@ -192,10 +190,7 @@ const state_proxy_handler = {
192190
(effect_active() || updating_derived) &&
193191
(!(prop in target) || get_descriptor(target, prop)?.writable)
194192
) {
195-
const previous_owners = current_owners;
196-
if (DEV) set_current_owners(metadata.owner);
197-
s = (metadata.i ? source : mutable_source)(proxy(target[prop], metadata.i, metadata.owners));
198-
if (DEV) set_current_owners(previous_owners);
193+
s = (metadata.i ? source : mutable_source)(proxy(target[prop], metadata.i, metadata.o));
199194
metadata.s.set(prop, s);
200195
}
201196

@@ -237,7 +232,7 @@ const state_proxy_handler = {
237232
if (s !== undefined || (effect_active() && (!has || get_descriptor(target, prop)?.writable))) {
238233
if (s === undefined) {
239234
s = (metadata.i ? source : mutable_source)(
240-
has ? proxy(target[prop], metadata.i, metadata.owners) : UNINITIALIZED
235+
has ? proxy(target[prop], metadata.i, metadata.o) : UNINITIALIZED
241236
);
242237
metadata.s.set(prop, s);
243238
}
@@ -253,15 +248,15 @@ const state_proxy_handler = {
253248
const metadata = target[STATE_SYMBOL];
254249
const s = metadata.s.get(prop);
255250
if (s !== undefined) {
256-
set(s, proxy(value, metadata.i, metadata.owners));
251+
set(s, proxy(value, metadata.i, metadata.o));
257252
} else if (DEV) {
258253
// TODO transfer ownership, in case it differs
259254
}
260255
const is_array = metadata.a;
261256
const not_has = !(prop in target);
262257

263-
if (DEV && metadata.owners) {
264-
check_ownership(metadata.owners);
258+
if (DEV && metadata.o) {
259+
check_ownership(metadata.o);
265260
}
266261

267262
// variable.length = value -> clear all signals with index >= value

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

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -110,20 +110,6 @@ export let current_component_context = null;
110110

111111
export let updating_derived = false;
112112

113-
/**
114-
* Used to assign ownership to signals in dev mode
115-
* — see `./dev/ownership.js` for more details
116-
* @type {Function[] | null}
117-
*/
118-
export let current_owners = null;
119-
120-
/**
121-
* @param {Function[] | null} owners
122-
*/
123-
export function set_current_owners(owners) {
124-
current_owners = owners;
125-
}
126-
127113
/**
128114
* @param {null | import('./types.js').ComponentContext} context
129115
* @returns {boolean}
@@ -1925,7 +1911,7 @@ export function push(props, runes = false, fn) {
19251911
if (DEV) {
19261912
// component function
19271913
// @ts-expect-error
1928-
current_owners = [(current_component_context.function = fn)];
1914+
current_component_context.function = fn;
19291915
}
19301916
}
19311917

@@ -1948,10 +1934,6 @@ export function pop(component) {
19481934
}
19491935
}
19501936
current_component_context = context_stack_item.p;
1951-
if (DEV) {
1952-
// @ts-expect-error
1953-
current_owners = current_component_context ? [current_component_context.function] : null;
1954-
}
19551937
context_stack_item.m = true;
19561938
}
19571939
// Micro-optimization: Don't set .a above to the empty object

packages/svelte/src/internal/client/types.d.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@ export type SourceSignal<V = unknown> = {
8282
export type SourceSignalDebug = {
8383
/** This is DEV only */
8484
inspect: Set<Function>;
85-
/** This is DEV only */
86-
proxy?: ProxyStateObject;
8785
};
8886

8987
export type ComputationSignal<V = unknown> = {
@@ -409,7 +407,7 @@ export interface ProxyMetadata<T = Record<string | symbol, any>> {
409407
/** The original target this proxy was created for */
410408
t: T;
411409
/** Dev-only — the components that 'own' this state, if any */
412-
owners: null | Set<Function>;
410+
o: null | Set<Function>;
413411
}
414412

415413
export type ProxyStateObject<T = Record<string | symbol, any>> = T & {

0 commit comments

Comments
 (0)