dot-dom icon indicating copy to clipboard operation
dot-dom copied to clipboard

JSX support?

Open mindplay-dk opened this issue 6 years ago • 9 comments

Any chance for JSX support?

I tried adding a JSX-compatible wrapper-function myself, but so far just found new and interesting ways to make the H function explode ;-)

This got me some of the way, but doesn't work for text nodes yet...

/** @jsx make*/

const make = (type, props, ...children) => H(type, props || {}, ...children);

Any particular reason the H function signature doesn't resemble a "normal" virtual DOM factory function?

mindplay-dk avatar Feb 15 '19 14:02 mindplay-dk

Hello there @mindplay-dk !

Any particular reason the H function signature doesn't resemble a "normal" virtual DOM factory function?

Do you have some reference in mind? I modelled it (as close as it can get in 512 bytes) having react's createElement in mind : https://reactjs.org/docs/react-api.html#createelement

Let me give it a try with JSX myself and I might have some more feedback for you ;)

wavesoft avatar Feb 16 '19 13:02 wavesoft

Oh I think I found the issue. JSX uses null if there are no properties defined. This library cannot handle this. It can do undefined, {} or even [] just fine, but null will cause issues.

wavesoft avatar Feb 16 '19 20:02 wavesoft

JSX uses null if there are no properties defined. This library cannot handle this.

This should be on the list of caveats maybe?

If supporting JSX is a non-goal, maybe this should be stated in the documentation as well? Many people will see the JSX-like H factory function and the word "VDOM", and will assume it'll work, as it does with almost any library of this type.

I expect JSX-support is just a simple one-liner though - even if the library doesn't support it, perhaps an example wrapper-function could be added to the documentation?

mindplay-dk avatar Feb 17 '19 10:02 mindplay-dk

This should be on the list of caveats maybe?

For now, totally, but I would also like to somehow support it...

JSX was not my first priority so I never tested it to be honest... I based my initial API on React when I started, but due to the size constraints I decided to sacrifice some of the features. (Don't forget that the manifesto of this library is to never exceed the 512 bytes in size 🙂)

wavesoft avatar Feb 17 '19 11:02 wavesoft

The devel/0.3.1 branch should now also support null 💪

wavesoft avatar Aug 21 '19 11:08 wavesoft

Wow. This just works?! With one line of code?! 😂

https://codesandbox.io/s/jsx-with-dot-dom-jjdzy

Props, state, state-updates, updates to a parent component, everything just works.

That's CRAZY cool.

I think maybe now you can put this JSX one-liner in the docs and show off JSX support? 😀

mindplay-dk avatar Sep 30 '19 15:09 mindplay-dk

Technically you should be able to do just

/** @jsx H */

wavesoft avatar Oct 05 '19 14:10 wavesoft

Apparently, yep. (I don't recall why I thought a function was necessary before...)

mindplay-dk avatar Oct 05 '19 16:10 mindplay-dk

Okay, so I recall now, #31 for one is something I wanted to address - as well as support for other literals like true and false.

So I would maybe hold off on announcing JSX support, as it's probably going to be a bit too confusing for someone to use in practice right now.

mindplay-dk avatar Oct 06 '19 16:10 mindplay-dk