-
Notifications
You must be signed in to change notification settings - Fork 35
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 equivalent? #8
Comments
Oh yes, using custom markup engine would take +10000 |
Hi, thank you guys for your interest on this project. Currently we support an element building DSL as a replacement of JSX (see below) def render
div do
h1 { "Title" }
h2 { "subtitle"}
div { span { "some text #{interpolation}"} }
present FancyElement
end
end Is this something you guys want? |
Since the reason why JSX exist is that Javascript is not expressive enough to make building DOM hierarchy easily (all the But in Ruby this would not be a problem. That's why a element building DSL could be easily designed. And if your goal is to separate Hope this will clarify 😄 |
Hi would it be possible to do something like this? def render
present <<-HTML
<div>
<h1>#{title}</h1>
</div>
HTML
end def render
present <<-HTML
<div>
<h1>%{title}</h1>
</div>
HTML
end I don't know enough about the react/opal internals to know if this is doable. However I do think this could be more "readable" for a developer. |
This is a matter of taste (and maybe my background), but this:
looks more readable to me than this: def render
present <<-HTML
<div>
<h1>%{title}</h1>
</div>
HTML
end @zetachang for what's it worth, I think you are on the right track with the Ruby DSL vs HTML. 👍 |
@vais I guess it depends on ones background. I'm actually more interested if it would be possible to do it like that. I see that the JSX translates the "HTML" part to individual node creation calls, I guess that the overhead of parsing the HTML at runtime would be deadly to performance. So the only way would be for OPAL to understand that the <<-HTML section should be transpired to react specific code, which I don't see happening. Maybe something like this would be possible instead: def render
present <<-HTML.react_jsx
<div>
<h1>%{title}</h1>
</div>
HTML
end But that starts to become less clean. |
Just came up with some approach to avoid modifying the compiler: def render
%x{
<div>
<h1>#{title}</h1>
</div>
}
end This would get compiled to JS, by feeding this to a JSX transpiler, we would get valid JS as result. But still some issues needed to be addressed.
Above is the easy way, the hard way may be rolling out our own transpiler which compile HTML markup inside your code to valid Ruby code (just as JSX did). Which will allow you to write, def render
<div>
<h1>#{title}</h1>
</div>
end |
It should work chaining with the react compiler, not sure about es6. Also i suggest to use |
It's released in latest 0.1.0. Feel free to reopen it if you got any other concerns or suggestion. 😉 |
This issue was moved to ruby-hyperloop/hyper-react#8 |
Any plans for including a markup DSL like JSX?
To give this a Ruby flavor, maybe let users embed Haml or Slim markup?
The text was updated successfully, but these errors were encountered: