-
-
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
Allow user of component to specify event and bind ordering. #7415
Comments
As mentioned in the other issue, components can expose these kinds of options through their API: <script>
export let value;
export let prebinding = false;
</script>
{#if prebinding}
<input on:change bind:value />
{:else}
<input bind:value on:change />
{/if} Components are compiled individually, so even with the proposed compiler option we wouldn't be able to decide at build-time what order to pick and it'd have a similar runtime hit (at minimum).
I get the intention, and it sounds sensible to want a way for component attribute order to behave similarly to tag attribute order. On the other hand, it'd cause confusion as to why the order matters for some components but not others. Implementation-wise, I'm not even convinced it's possible to come up with a satisfying behavior that handles all cases. For example, what should we do when we have forwarded events and bindings amongst actions and non-forwarded events? <!-- Input.svelte -->
<input use:foo on:change use:bar bind:value />
<!-- Component.svelte -->
<Input bind:value on:change={handle}/> Would this be
I don't think it's that clear. Anecdotally, I've personally never used both a binding and an event at the same time while giving the binding priority. |
Describe the problem
The order of event and bind attributes matters in svelte, (See #4616).
It is currently possible to forward events from components. It is not possible to specify the order in which these events are fired.
Describe the proposed solution
Allow a component to specify the order of its events and binds are to be set by the caller.
The exact implementation of this, I'm not sure.
Maybe it could be an option?
Then the order of
bind:value
andon:change
will be set on the parent component instead.Alternatives considered
Making use of sensible defaults, it's probable a user will want the
bind
before the events.Importance
would make my life easier
The text was updated successfully, but these errors were encountered: