JSX Support #1618
Replies: 8 comments
-
Posted at 2022-06-07 by @gfwilliams Wow, that's impressive! I'm a bit new to this, but how does JSX normally work? Obviously if I paste this into a browser or Node.js, I get I'm a bit iffy about building stuff into the interpreter itself that isn't part of the default JS spec - for instance looking at the changes I believe that the line At the end of the day, Espruino really isn't anywhere near React, so I think if people start thinking the layout library behaves like it they will ultimately end up confused/disappointed. However if we could actually just turn this into a generic XML parser then that could be awesome, and we could build functionality a bit like you're suggesting right in:
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2022-06-08 by g_lander JSX is usually transpiled by the TypeScript compiler or Babel.
As per having a string and parsing it, there are multiple pitfalls, some of them which are described in the original JSX spec:
I see why people would be confused as to why JSX is used in a different way versus React, but using Layout requires reading the docs (or examples) beforehand, so if the usecase of JSX can be explained there, I don't think it will be a problem. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2022-06-08 by @gfwilliams Thanks! I'd be interested to hear other people's views on this, but personally I don't see a massive difference in readability between these two:
Because the Bangle is so constrained and the screen is small, you're never going to be able to have a lot of stuff in the Layout, so I really don't see a big benefit in this - and actually having a whole new syntax and parser that isn't JS and isn't quite JSX just for a few lines of code in a few apps seems like massive overkill, especially on Bangle.js 1 where we're starting to have to worry about how big the Espruino binary is so it'll fit in the available flash. This is undoubtedly cool, but I just think for Bangle.js, it's too much. I guess if you really wanted you could add a plugin to EspruinoTools that detected JSX on the PC, parsed it and rewrote it into a JS object, but I'm conscious that much like the TypeScript support this will probably be something that gets added, used for one app, and then forgotten about. A built in XML parser though? That would actually be useful for loads of people - especially with the HTTP request support added to |
Beta Was this translation helpful? Give feedback.
-
Posted at 2022-06-08 by Serj Hi! Сorrect the typo, otherwise people won't understand why it's written that way :)
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2022-06-08 by Serj In fact, I also thought it would be fun if it was possible to use JSX in B.js, but I would also like to have concepts like hooks. In general, I would expect concepts from the React world. JSX and React are very popular, this is already a certain standard for the web-dev and if the same concepts could be applied to a microcontroller, then it would be fun :) Also, in theory, it would add popularity to the project, new users, because the world of React is huge. However, there must be a person who will do this: create and maintain JSX React transpiler into the Espruino JS code. As a plugin for Babel or something else. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2022-06-08 by TheLogan I work with React at my job, and I really do love that stuff. The way React actually works is by transpilation typescript/bable/webpack magic This
Becomes this
It wouldn't under any circumstances be part of the interpreter, but I don't know if it's a good investment of time.. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2022-06-08 by TheLogan I found this tool, it transpiles React live to actual Javascript. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2022-06-18 by g_lander I'm worried that using a normal JS library would cause memory problems - in some other posts, it can be seen that the Bangle.js 1 is struggling with memory in some posts in some cases. I think I have to agree with Gordon that the upper limit for UIs on the Bangle.js is not that high to warrant very complex UI frameworks.
to
, though I could see why part-improvised syntax and grammar might be frowned upon. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2022-05-29 by g_lander
I like the Bangle.js Layout library, and I like React. Both are similar, in my opinion. One thing React has which Layout doesn't is JSX: Instead of having to write object literals or function calls, it can be something which looks like HTML or XML.
For example:
instead of
I think it would be cool if the Espruino interpreter supported some form of JSX, since it would make Bangle.js Layout code be easier to read.
I've made a local branch which implements JSX in the interpreter.
I think there can be a problem with JsHint not supporting it and stuff, but maybe it can remedied by updating CodeMirror to use ESLint?
Beta Was this translation helpful? Give feedback.
All reactions