-
Notifications
You must be signed in to change notification settings - Fork 121
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
Feature request: Directives for components #96
Comments
I think the other thing to solve is spreads if we want components to be able to forward these. This proposed solution came up during 1.0 rc time period but ultimately wasn't a fan of the inconsistency. Mostly that it puts onus on the component author to forward ref/the right ref. These directives simply may or may not work depending, or not work as expected. Use could only apply to the main ref if multiple were forwarded. Expects precisely a DOM element. There are a lot of unexpected potential. Svelte doesn’t support this and Im ok with not as well. |
This issue came up again recently in #help, where it was surprising that I wonder if it makes sense to handle directives when spreading them into Elements. (This may be what Ryan was suggesting.) Then a component could implement/override/whatever directives if they want, and can pass on other directives via spread. At first I worried that this wouldn't play well with TypeScript. A component would seemingly need to specify/know every directive they could accept. But explicit enumeration can be avoided: we could say tyat a component can take arbitrary directives using the type |
I think part of the issue with |
I had the following behavior in mind:
This is very close to the current behavior, which just does case 2 in all cases. I'm proposing changing the behavior when you get a native element. I'm not exactly sure how ergonomic the DX would be here, but this change to |
IMO a workable solution for this is the following:
Reasoning:
Basically if being able to attach directives to different elements inside a single custom component is desirable I don't see any other option. If that's not desirable it's probably possible to introduce like a special |
First, whatever we decide here in general, even if it's "do nothing", I think we should modify Now, reflecting on this issue more, I'm now much more inclined to go with @lxsmnsyc's original suggestion (instead of modifying
I think this is nicely consistent, and easy to teach and understand. The current docs say The arguments against this are that " With this proposal, the user of a directive (whoever writes On the TypeScript side, one issue is that interface dom-expressions/packages/dom-expressions/src/jsx.d.ts Lines 63 to 65 in df04869
Hopefully we can extend |
Currently, the code
<Counter use:example="Hello World" />
compiles intoWe could probably make it work into
since
ref
is already a special prop for both host and components.What do you think?
The only design challenge would be that
props.ref
can be assigned anytime, anywhere which makes it lack constraint unlike host nodes, posing some memory leaks.The text was updated successfully, but these errors were encountered: