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

JSX support? #51

Open
mindplay-dk opened this issue Feb 15, 2019 · 9 comments
Open

JSX support? #51

mindplay-dk opened this issue Feb 15, 2019 · 9 comments

Comments

@mindplay-dk
Copy link

mindplay-dk commented Feb 15, 2019

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?

@wavesoft
Copy link
Owner

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
Copy link
Owner

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.

@mindplay-dk
Copy link
Author

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?

@wavesoft
Copy link
Owner

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
Copy link
Owner

The devel/0.3.1 branch should now also support null 💪

@mindplay-dk
Copy link
Author

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? 😀

@wavesoft
Copy link
Owner

wavesoft commented Oct 5, 2019

Technically you should be able to do just

/** @jsx H */

@mindplay-dk
Copy link
Author

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

@mindplay-dk
Copy link
Author

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.

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

2 participants