Skip to content
Discussion options

You must be logged in to vote

Those are internals which can break at any point, so I would not recommend that.

You could write the attachment in such a way that you can just add arbitrary objects, though you will have to manually supply types in that case (e.g. in a factory function), the usage would look something like:

<script lang="ts">
	import { createPropsAttachments } from './element-attachments.js';

	let div;

	// can also be extracted to a module for sharing
	const attachProps = createPropsAttachments<{ a: number, b: string }>();

	$effect(() => {
		const { a, b } = attachProps.for(div);
	});
</script>

<div
	bind:this={div}
	{@attach attachProps({ a: 1, b: '2' })}>
	An element
</div>

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@HighFunctioningSociopathSH
Comment options

@brunnerh
Comment options

Answer selected by HighFunctioningSociopathSH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants