-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement <svelte:target> special component. #1321
Comments
#1321 and #1322 together would turn this code: https://svelte.technology/repl?version=1.60.2&gist=196319d9223a4cde1db09b4a6805094c Into this code: https://svelte.technology/repl?version=1.60.2&gist=a736a723115f05d8aa0fbf1baeeccc2e I think that's a much cleaner and more Svelte-esque solution than manually manipulating the DOM like in https://github.com/sveltejs/svelte/blob/master/test/runtime/samples/action/main.html. |
I like this idea. |
I was thinking, in order to make this easily integrate into existing components, we can prevent the user from putting markup inside it, like the <:Target on:mouseover="set({'show': true})" on:mouseout="set({'show': false})" />
{{#if show}}
<span class="tooltip">{{text}}</span>
{{/if}} |
I see where you're headed with this, but something about it feels like the wrong approach. Haven't been able to put my finger on it yet. Are there any viable alternatives? I think it might be the case that allowing code to "target" something parent that easily would lend itself too easily to spaghetti code, but then again that's sort of what bindings do. </svelte:scratches-head> |
If there's another way to have two components operate on the same element, that could work. What I'm thinking is, without intentional spaghetti code, there isn't a way to have a component for styling and a component for routing, for example, both operate on an Edit: At least, that's the currently possible way to do it Svelte-ily. You can, of course just have a Svelte component to provide the scaffolding around DOM manipulation. |
I'm not officially for or against this—I can see the utility—but it does still seem like a rabbit hole to me. It goes against the grain of self contained components and wouldn't work well with a component marketplace...you'd have to specify that component a only works with component b. Another question: wasn't this what decorators were included for? Or is that orthogonal. I dunno. Your particular use case makes sense. I'm just wondering aloud (for the sake of thinking through it) whether components need to be loosely or more tightly coupled. One problem that actually goes beyond the scope of this solution is that in plain vanilla applications, DOM interacts with DOM all over the place. So maybe we ought to expand the scope of your particular use case. Examples:
So here's my broader question. How does one, in a sveltish way, span the interactive DOM gap (without decorators?) and without spaghetti code? (Or is decorators THE answer?) In theory, app-level Store variables and observers answer this, but maybe there needs to be a bigger idea here. In sum, this is a common problem I've encountered in these types of frameworks (Ractive had the problem) and I have yet to hear a really satisfying solution. |
I'm going to close this for the reasons in #1355 (comment), and because I haven't heard this feature request other than in this issue |
Having a
<svelte:target>
special component that references the component's target element would be really useful instead of having to useaddEventListener
onthis.options.target
.Basically, turn this:
Into this:
Or maybe this:
And make it a lot easier to do things like this:
Edit: Updated for v2.
The text was updated successfully, but these errors were encountered: