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 #179
Comments
neat. i feel like additional pre-processing work would be required to translate 100% - if it's even possible. especially vnode's special additionally, domvm's |
a TypeScript declaration file would be much more useful, IMO, as it would provide API discoverability and autocomplete for anyone using this lib with VSCode. i have one started but it's far from finished as i'm not very well versed in finer details of the format. |
You could alway explicitly call domvm in the views. https://jsfiddle.net/wubt3xzr/1/ I'm not a fan of JSX, but it's easier to convince others to move away from React with JSX support. |
beautiful!...NOT 😜 if that's all the code that's required, then the perf overhead for that wrapper should be pretty negligible over |
btw, once enough JSX enthusiasts have sufficiently dogfooded your JSX pragma, we can add it to the docs inline. |
Using Thanks. |
i don't use React or JSX, so it's hard for me to tell from JSX examples where JSXisms end and Reactisms begin. how does it handle domvm's <MyButton color="blue" shadowSize={2}>... someone would need to go through https://github.com/leeoniya/domvm#templates and document what can and cannot be supported by JSX. |
Thank you @leeoniya for the quick response. I will have a closer look at the issues that you have raised and try to come up with some examples. In the meantime, I'll say that simple/plain JSX seems to work well with what I stated above, so that's a good start. |
@foxdonut I don't think this will work with components. Have you written a component that works with this? |
@iamjohnlong since I am new to domvm, would you mind showing exactly what you mean by "component"? Could you show an example of what it does that cannot be accomplished with plain functions and using |
there are a few examples in the demo's, http://leeoniya.github.io/domvm/demos/playground/#table-filter docs are here https://github.com/leeoniya/domvm#sub-views-vs-sub-templates "Sub views" being a component. This fiddle shows the use of a component https://jsfiddle.net/kqurpfqk/ and why the wrapper pragma is needed. |
@iamjohnlong thanks, that is very helpful. I understand components and sub-views better now. My personal preference would be to use sub-templates instead of sub-views, and plain functions instead of JSX components. For example, I would change https://jsfiddle.net/foxdonut/01afeq9h/ It's not as "JSX-y", but like I said, I favour plain function calls. Then The table-filter example is very interesting and greatly helped me understand components and views in domvm. Again, while I'm not knocking this approach, I still favour plain functions. This would be my take on it: https://codepen.io/foxdonut/pen/XzBVmN?editors=0010 Some advantages include:
It's trivial to use JSX: https://codepen.io/foxdonut/pen/WXKMwR?editors=0010 Finally, because the view is a function of the model, you can have a dev tool that can record and tracer back through model snapshots, and also allow you to type in a model directly and see the resulting view: https://codepen.io/foxdonut/pen/vWadgB?editors=0010 @leeoniya Please know that I understand that you don't like JSX, but I was hoping to figure out if this simple approach would make JSX easy to use for those who want to. I've been exploring many virtual-DOM libraries and |
@foxdonut whatever floats your boat man. that's one of the great things about domvm, is that it's flexible and doesn't force you into one pattern. |
@iamjohnlong agreed! really liking domvm. My original concern was simply whether using JSX in this simple manner with domvm had any obvious/glaring disadvantages. |
One thing I notice is that the inner functions like |
@tropperstyle that's a good point. Normally, I would organize the code slightly differently such that That being said, I'm not certain about parameterized handlers, i.e. a function that takes a parameter and returns a handler function. Would those be recreated on each render, and how much impact would that have on performance or memory consumption? How does using domvm's parameterized handlers, I'd be interested in the differences there and their consequences. |
thanks for the praise 😊
if you're just using JSX as a way to avoid
function recreation and re-binding is really cheap. i wouldn't worry about it until you have hundreds of handlers or extremely numerous/rapid
all parameterized handlers bind the same proxy handler, so they will not get recreated or rebound. the parameterized array you provide just sits on the linked vnode and the proxy handler executes it at runtime when an event fires. |
@leeoniya everything you said makes a lot of sense. thank you for the explanations. I agree with you, using domvm's functions definitely results in more powerful and uniform code. Still, it's nice to know that you can get a great deal of domvm's features with JSX and can work nicely say in an application where you don't need svg. To answer your original question, here are the JSX equivalents of https://github.com/leeoniya/domvm#templates : https://codepen.io/foxdonut/pen/KyBzmy?editors=0010 Finally just to clear up the "Reactism vs JSXism" question, there really is no React involved here at all. JSX simply gets translated to Cheers and thanks again for |
that's pretty cool :) i don't foresee adding explicit support for JSX in domvm. but rather than keeping these brain-dumps/experiments in a permanently open issue, would you guys want to put this into a JSX wiki section here and i'll link to it from the main readme? afterwards we can close this out and anyone can add more to the wiki as they see fit. |
@leeoniya great idea. I added a Wiki page: https://github.com/leeoniya/domvm/wiki/JSX |
would you mind adding the contents of the codepen and jsfiddle directly to the wiki? i'd prefer not to rely on external services to host code samples (if you couldn't tell from my from-scratch demo playground impl ;). you can still leave the links, though. |
Done! |
thanks! i've added it to the readme: https://github.com/leeoniya/domvm#jsx |
I created an example of how to wire in JSX here https://jsfiddle.net/kqurpfqk/
Just an experiment, but I wanted to share. I'm curious of the perf impact which I will be testing soon.
The text was updated successfully, but these errors were encountered: