Skip to content

Commit 083359d

Browse files
committed
add attachments symbol
1 parent 35b9d21 commit 083359d

File tree

5 files changed

+29
-13
lines changed

5 files changed

+29
-13
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { ATTACHMENTS_SYMBOL as AttachmentsKey } from '../internal/client/constants.js';
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/**
2+
* A unique symbol used for defining the attachments to be applied to an element or component.
3+
*/
4+
export const AttachmentsKey: unique symbol;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ export const STATE_SYMBOL = Symbol('$state');
2525
export const STATE_SYMBOL_METADATA = Symbol('$state metadata');
2626
export const LEGACY_PROPS = Symbol('legacy props');
2727
export const LOADING_ATTR_SYMBOL = Symbol('');
28+
export const ATTACHMENTS_SYMBOL = Symbol.for('svelte.attachments');

packages/svelte/src/internal/client/dom/elements/attributes.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { get_descriptors, get_prototype_of } from '../../../shared/utils.js';
44
import { create_event, delegate } from './events.js';
55
import { add_form_reset_listener, autofocus } from './misc.js';
66
import * as w from '../../warnings.js';
7-
import { LOADING_ATTR_SYMBOL } from '../../constants.js';
7+
import { ATTACHMENTS_SYMBOL, LOADING_ATTR_SYMBOL } from '../../constants.js';
88
import { queue_idle_task } from '../task.js';
99
import { is_capture_event, is_delegated, normalize_attribute } from '../../../../utils.js';
1010
import {
@@ -416,8 +416,11 @@ export function set_attributes(
416416
}
417417
}
418418

419-
for (let symbol of Object.getOwnPropertySymbols(next)) {
420-
attach(element, () => next[symbol]);
419+
const attachments = next[ATTACHMENTS_SYMBOL];
420+
if (attachments) {
421+
for (let attachment of attachments) {
422+
attach(element, () => attachment);
423+
}
421424
}
422425

423426
return current;

packages/svelte/types/index.d.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,13 @@ declare module 'svelte/action' {
593593
export {};
594594
}
595595

596+
declare module 'svelte/attachments' {
597+
/**
598+
* A unique symbol used for defining the attachments to be applied to an element or component.
599+
*/
600+
export const AttachmentsKey: unique symbol;
601+
}
602+
596603
declare module 'svelte/animate' {
597604
// todo: same as Transition, should it be shared?
598605
export interface AnimationConfig {
@@ -1881,10 +1888,10 @@ declare module 'svelte/motion' {
18811888
* const tween = Tween.of(() => number);
18821889
* </script>
18831890
* ```
1884-
*
1891+
*
18851892
*/
18861893
static of<U>(fn: () => U, options?: TweenedOptions<U> | undefined): Tween<U>;
1887-
1894+
18881895
constructor(value: T, options?: TweenedOptions<T>);
18891896
/**
18901897
* Sets `tween.target` to `value` and returns a `Promise` that resolves if and when `tween.current` catches up to it.
@@ -1903,21 +1910,21 @@ declare module 'svelte/motion' {
19031910

19041911
declare module 'svelte/reactivity' {
19051912
export class SvelteDate extends Date {
1906-
1913+
19071914
constructor(...params: any[]);
19081915
#private;
19091916
}
19101917
export class SvelteSet<T> extends Set<T> {
1911-
1918+
19121919
constructor(value?: Iterable<T> | null | undefined);
1913-
1920+
19141921
add(value: T): this;
19151922
#private;
19161923
}
19171924
export class SvelteMap<K, V> extends Map<K, V> {
1918-
1925+
19191926
constructor(value?: Iterable<readonly [K, V]> | null | undefined);
1920-
1927+
19211928
set(key: K, value: V): this;
19221929
#private;
19231930
}
@@ -1927,7 +1934,7 @@ declare module 'svelte/reactivity' {
19271934
}
19281935
const REPLACE: unique symbol;
19291936
export class SvelteURLSearchParams extends URLSearchParams {
1930-
1937+
19311938
[REPLACE](params: URLSearchParams): void;
19321939
#private;
19331940
}
@@ -1999,7 +2006,7 @@ declare module 'svelte/reactivity' {
19992006
*/
20002007
export function createSubscriber(start: (update: () => void) => (() => void) | void): () => void;
20012008
class ReactiveValue<T> {
2002-
2009+
20032010
constructor(fn: () => T, onsubscribe: (update: () => void) => void);
20042011
get current(): T;
20052012
#private;
@@ -2064,7 +2071,7 @@ declare module 'svelte/reactivity/window' {
20642071
get current(): number | undefined;
20652072
};
20662073
class ReactiveValue<T> {
2067-
2074+
20682075
constructor(fn: () => T, onsubscribe: (update: () => void) => void);
20692076
get current(): T;
20702077
#private;

0 commit comments

Comments
 (0)