Skip to content
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

more svelte action ideas #13

Open
swyxio opened this issue Jan 15, 2021 · 9 comments
Open

more svelte action ideas #13

swyxio opened this issue Jan 15, 2021 · 9 comments

Comments

@swyxio
Copy link
Owner

swyxio commented Jan 15, 2021

https://mobile.twitter.com/lihautan/status/1350083142833487874/photo/1

@swyxio
Copy link
Owner Author

swyxio commented Jan 20, 2021

devon govett suggests the hooks from his React Aria package https://github.com/adobe/react-spectrum/tree/main/packages/@react-aria/interactions/src

@dkzlv
Copy link
Contributor

dkzlv commented Jan 20, 2021

Since Svelte does not have a way to forward all the events from a DOM node (e.g., on:* — which I think is so bad it should never be shipped to Svelte) we're stuck with UI Kits that forward everything by hand.

I came up with an action, that will open up an react-alike API for events.

Child.svelte

<script>
	import { subscribeToEvents } from './utils.js';
	
	export let events;
</script>

<div use:subscribeToEvents={events}>
	Hey
</div>

Parent.svelte:

<script>
	import Child from './Child.svelte';
	
	const events = new Map();
	events.set('mouseover', () => console.log('mouseover'))
	events.set('click', () => console.log('click'))
</script>

<Child {events} />

I can update it to look better, but the idea stands.

@swyxio
Copy link
Owner Author

swyxio commented Jan 20, 2021

thank you for suggesting! this usecase looks a bit a bit abstract imo. mostly useful for library builders? would prefer to document in recipes then unless there is more popular demand.

@dkzlv
Copy link
Contributor

dkzlv commented Jan 21, 2021

@sw-yx I'm on the same page with you. I came up with this action while discussing Svelte's potential with React folks, I have yet to find a single use-case in my real-world practice for it.

But I was told by the same React folks that every major company creates an in-house UI Kit, and being unable to work with events predictably pushes them away from adopting Svelte. I'm not sure if this belongs in this repo, recipes, tutorials or whatever. For now other guy from the same chat put the solution on the corresponding feature request on Svelte's main repo, hopefully it'll help someone.

@jthegedus
Copy link

jthegedus commented Jan 26, 2021

Is there a way to extract the active link action from svelte-spa-router https://github.com/ItalyPaleAle/svelte-spa-router#highlight-active-links

@swyxio
Copy link
Owner Author

swyxio commented Feb 1, 2021

@jthegedus this maaaybe could be interesting - do you think most routers would have an opinion on how to do active links though?

i'm sure if we wanted to we could extract it, just want to make sure it is useful by most. i think this is ok...

@dkzlv
Copy link
Contributor

dkzlv commented Feb 2, 2021

Beautiful idea! Revising how I achieved this in my project can't help but think an action would be more reusable.

But just compare the code required for this task. It's monstrous for a reusable solution and barely 4 LOC for a sapper-specific one. Makes me think if it would really be useful.

@jthegedus
Copy link

do you think most routers would have an opinion on how to do active links though

Most routers will certainly have an opinionated way of doing this. The fact that not all routers come with this action standard is the real issue. Is there a way to ensure that SvelteKit/all Svelte routers come with this action? Although Sapper only needs a 4LOC implementation as @dkzlv notes, it's 4 lines people have to lookup, understand, implement, and maintain as the router changes over time. I just want use:active everywhere 😅

@swyxio
Copy link
Owner Author

swyxio commented Feb 2, 2021

i think its a valid thing to want. i have no insider info on what sveltekit will offer. we definitely dont have any dictat on what routers will have this action.

You know what - I'll add this to readme for now. can add if we have popular demand/once sveltekit comes out and doesnt have it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants