woutdp / live_svelte

Svelte inside Phoenix LiveView with seamless end-to-end reactivity
https://hexdocs.pm/live_svelte
MIT License
1.01k stars 38 forks source link

Suggest renaming LiveSvelte.render to LiveSvelte.svelte #48

Closed dev-guy closed 1 year ago

dev-guy commented 1 year ago

Now that I have more experience with Phoenix components, it seems that <.foo> in heex templates should be a noun - a component name - instead of a verb. Therefore I am suggesting deprecating LiveSvelte.render in favor of LiveSvelte.svelte so that it is more in the spirit of .button, .link, etc.

woutdp commented 1 year ago

Makes sense to make it a noun, but not sure if LiveSvelte.svelte is better than LiveSvelte.render as it feels redundant to have svelte twice in the name. If we can make it LiveSvelte that would be better though. Open to other suggestions too

dev-guy commented 1 year ago

Something like CommonComponents.button turns into < .button>. Can the import and/use keywords do the same for LiveSvelte?

woutdp commented 1 year ago

Interesting, worth looking into. I'd be happy with <.svelte /> for example!

dev-guy commented 1 year ago

I was able to get < .render> working and make ~V work by adding

 import LiveSvelte

to MyAppWeb.html_helpers()

With this import statement in html_helpers(), it does not need to be in live_view() to make ~V work.

On the other hand, it seems to be more conventional for Phoenix components to make themselves available via 'use' but "use LiveView" doesn't work.

woutdp commented 1 year ago

Interesting, if you have some code to show or make a PR I'd be happy to merge it, if .render works I think we can make .svelte work too. We should probably also add a deprecated statement to the previous way of doing things :)

dev-guy commented 1 year ago

https://github.com/dev-guy/phoenix-ash-svelte-flowbite/pull/16/files

I don't think there's much to do for LiveSvelte.. perhaps rename render to svelte and create a new render (which is deprecated) that calls svelte()

dev-guy commented 1 year ago

Need to think whether you want .svelte or .livesvelte or .liveSvelte . Names matter! 🤔

woutdp commented 1 year ago

I think svelte makes sense, as that's what we're rendering. LiveSvelte as a package for me means it integrates nicely with LiveView, but the svelte components that are being rendered don't have a lot of extra functionality attached to them. They pass props, and there's the pushEvent function that's available, but that's about it. phx-click etc works out of the box.

So in a sense you can just use the package as regular svelte or go all the way and integrate with LiveView. Kind of want it to be the go to solution for Svelte inside Phoenix, that integrates nicely with all features of Phoenix, from dead views all the way to LiveViews and everything in between like components.

Wonder what your opinion is on the name? Which do you prefer?

aiwaiwa commented 1 year ago

My 2 cents. I wish regular <.live_component module={Something.Module} /> would actually one day become simply <Something.Module :live />. Do you think LiveSvelte could eliminate that extra tag altogether?

woutdp commented 1 year ago

LiveSvelte uses regular function components instead of live components, so we don't have that specific issue :)

dev-guy commented 1 year ago

.svelte is good with me. Sooner is better.

woutdp commented 1 year ago

Done, available in version 0.6.0. Render will still work but raises a deprecation warning