-
Notifications
You must be signed in to change notification settings - Fork 18
Description
I'm currently working on a bigger change and thought it would be a good opportunity to ask for some feedback.
Feel free to discuss these and maybe add other improvement ideas.
1. Prop Names
Prop Names are currently a mix of camelCase and lowercase. For example srcset, tabIndex and referrerPolicy.
The first two are HTML attributes, which are lowercase in the spec, but the latter is a property (not set via HTML), so it's camelCase.
Event Names are on another level: while they are technically available as HTML attributes, those are specified as strings on HTML, which is not what we want here, but internally, we always convert the names to lowercase when using addEventListener. The camelCase is currently needed though, in order to detect what props are events. This might change with the folling section though. See below.
As you can see, there is some inconsistency here and this should be cleaned up. I have 3 Options to choose from:
- Making everything adhere to the spec, i.E. HTML attributes are all lowercase, while properties can be uppercase.
- Making everything camelCase for better readability. After all, this is not HTML, it is JSX (
<div />is not valid HTML for example).
2. Event Listeners
Events are currently specified like this: onMyEvent or onMyEventCapture.
This was made in order to be more like react, but I'm not sure that's a good idea. It creates certain issues:
- We need a way to differentiate between plain values (for attributes) and events. Currently this is done by using a Regex
/^on\p{Lu}/u, which is ugly. - We need a way to add a modifier like "Capture". But we can currently only do
captureand not any of the 2 other modifiers addEventListener provides:passiveandonce. There is also a conflict with event names that end inCapturelikeonGotPointerCapture.
I'm thinking of changing this more to be like Vues approach. I.e. @click.capture, etc. In that case, event names could be all lowercase again like in the spec.
My question here is what values to allow:
- Vue allows changing the order of modifiers and that matters for vue in some cases (as they have other modifiers than just the 3 from addEventListener). I'm leaning to having a fixed order. For example
once, thenpassive, thencapture. I.e. you could do@click.once.captureand@click.capture.passive, but not@click.passive.once. This has the benefit of a bit of enforced code-style, while reducing the amount of possible properties on a JSX elements a lot! - I'm leaning towards not adopting the vue modifiers as well, like
stop,preventandself, since they are not part of the addEventListener call and they could probably be implemented by the user. Adding them within tsx-dom would make things more complicated, especially if order is supposed to be important.
edit: It seems, that @ is not a valid character to start a JSX prop with and . may not appear in the prop name either, so I'm looking for alternative characters:
- It seems I can use
:, but only exactly once (probably since it resembles namespaces).- Autocomplete/intellisense doesn't seem to work nicely on
:either, so aon:prefix is not a good option.
- Autocomplete/intellisense doesn't seem to work nicely on
- A dash can appear multiple times.
- But this makes typescript forget about type-checking.
$and_can appear multiple times without breaking anything.- So maybe something like
$click_once_capture?
- So maybe something like