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

RFC: Custom client directives #278

Closed
wants to merge 1 commit into from
Closed

Conversation

matthewp
Copy link
Contributor

@matthewp matthewp commented Aug 31, 2022

  • Start Date: 2022-08-31
  • Status: Draft

Summary

Provide an API on top of integrations to allow them to define custom client directives. An example usage would be:

---
import Counter from '../components/Counter.jsx';
---

<Counter client:interaction="hover" />

Links

@matthewp matthewp marked this pull request as ready for review August 31, 2022 16:58
@matthewp
Copy link
Contributor Author

matthewp commented Sep 6, 2022

  • Add about how we handle completions in VSCode.

@igorbt
Copy link

igorbt commented Dec 15, 2022

@matthewp , I'm glad to find this great proposal so well defined, I was thinking of something similar these days.

Would it be possible to make DirectiveOptions['value'] to be of any type? I'm not sure if being of type string is a limitation of the current directives implementation or not, but making it possible to pass more structured options to the custom directive would make it more usable and re-usable.

Building on the client:click directive example, maybe I have the "classic" counter component and I want to load and hydrate the component only on click on the buttons. Then I could give it options like this:

<Counter client:click={{
	selector: 'button',
}}/>

where selector is a CSS selector within the element that would trigger it. With the current proposal I cannot reuse the same click directive for several use-cases, I need to keep creating new ones and give them different names / keys.

Then we may even think of a pretty generic client directive like client:interactive that would cover probable 90% of use-cases:

<Counter client:interactive={{
	event: 'click',
	selector: 'button',
	loadingClass: 'loading',
}}/>

What do you think?

@wassfila
Copy link

using client directives, always result in a minimal client script, that runs, monitor then event, purpose is to deferr loading more scripts for later. Some directives are good and intuitive, increasing this to become more custom is not far from having code like this, when the dynamic import can be used and conditioned by any needed user logic. This can keeps code clarity over framework magic solutions.

<script>
	const card = await import('./Card')
	card.init_card(".card")
</script>

@Princesseuh
Copy link
Member

We've revamped our roadmap process! As such, this proposal goes back to being a Stage 1 proposal (albeit very much more advanced than the average one, so it might go back to Stage 2 and 3 very quickly), so we'll pursue discussion into the GitHub discussion thread: #272

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

Successfully merging this pull request may close these issues.

4 participants