Skip to content

Add support for each snippet. #14288

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
vhtmui opened this issue Nov 13, 2024 · 3 comments
Closed

Add support for each snippet. #14288

vhtmui opened this issue Nov 13, 2024 · 3 comments

Comments

@vhtmui
Copy link

vhtmui commented Nov 13, 2024

Describe the problem

Can not each the snippets.
Demo

<script>
	let {children, ...others} = $props();

	let fns = Object.keys(others);
</script>

<div>
	<!-- hope this work -->
	{#each others as other}
		{@render other?.()}
	{/each}

	<!-- this work but a bit verbose and not stable -->
	{#each fns as fn}
		{@render others[fn]()}
	{/each}
</div>

Describe the proposed solution

Wish to add a special prop similar to children, and can be enumerated directly

Importance

nice to have

@brunnerh
Copy link
Member

A special prop seems like overkill — maybe acceptable if it is a symbol, though I suspect that would still break things.

This can be simplified to:

{#each Object.values(others) as snippet}
  {@render snippet()}
{/each}

What is missing would be a function like isSnippet suggested in #9774 that would enable reliably filtering the values to just snippets.

@vhtmui
Copy link
Author

vhtmui commented Nov 13, 2024

A special prop seems like overkill — maybe acceptable if it is a symbol, though I suspect that would still break things.

This can be simplified to:

{#each Object.values(others) as snippet}
  {@render snippet()}
{/each}

What is missing would be a function like isSnippet suggested in #9774 that would enable reliably filtering the values to just snippets.

that's great too, hope it would be implemented.

@dummdidumm
Copy link
Member

Closing because this can be achieved with Object.values as shown by @brunnerh

@dummdidumm dummdidumm closed this as not planned Won't fix, can't repro, duplicate, stale Nov 13, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants