-
Notifications
You must be signed in to change notification settings - Fork 482
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
Improve Svelte use:inertia and <Link /> #1344
Conversation
With this they can be listened the Svelte way on HTML elements. ```svelte <a use:inertia={{ method: 'post' }} href="/toggle" on:success={({ detail }) => alert('Success!')}>Toggle</a> ```
Really nice Svelte-y PR |
@pedroborges Thanks so much for this. Are there any breaking changes here? |
@pedroborges Hey I tested this and it seems to work, so I merged in it lol. Would be good to know if there are any breaking changes here. Love that you were able to use Also, for the Link event callbacks, do these still won't work with return values, like we discussed in #237? I just tested this out, and returning <Link href="/users" on:before={() => false}>Users</Link> Or am I doing this wrong? This does seem to work — just not quite as nice: <a href="/users" use:inertia={{ onBefore: () => false }}>Users</a> |
None that I can think of.
This Svelte feature was only released a while ago. I'm glad the Svelte adapter can now have the
I think this is one downside of this approach, I'll play with it and see if there's any work-around for it. |
This PR brings a bunch of improvements to the
use:inertia
action and<Link />
component.use:inertia
Simplify options merge logic (#9eb66f6)
Stop dispatching the click event (#640f690)
It was a mistake to dispatch the
click
event withcreateEventDispatcher
from the action in first place. Its use is intended for components. We ran into an edge-case bug because of this in our own app.The element where
use:inertia
is used on can still have anon:click
handler or an event forwarder.Dispatch Inertia events on the HTML node (#00a4fa2)
This allows you to listen to Inertia event callbacks the Svelte way when using
use:inertia
.All event callbacks are supported:
on:cancel-token
,on:before
,on:start
,on:progress
,on:finish
,on:cancel
,on:success
, andon:error
. They also receive the samedetail
parameters as the Inertia event callbacks.<Link />
Add
as
prop (#7ff652a)You can now specify which HTML element the
<Link />
component should render.The
as
prop defaults to thea
HTML element.Remove duplicated logic (#7ff652a)
Previously the
<Link />
component anduse:inertia
action had a bunch of duplicated code. Now all this logic only exists on the action. The<Link />
component uses the action under the hood. This will make it easy to maintain both.Forward all Inertia callback events (#85d6704)