Rux: A JSX-inspired way to render view components in Ruby
1–10 of 42 posts
Re: Rux: A JSX-inspired way to render view components in Ruby
#2~~~ h('div.example', [
h('h1#heading', 'This is hyperscript'),
h('h2', 'creating React.js markup'),
h(AnotherComponent, {foo: 'bar'}, [
h('li', [
h('a', {href: 'http://whatever.com'}, 'One list item')
]),
h('li', 'Another list item')
])
])
);
~~~Re: Rux: A JSX-inspired way to render view components in Ruby
#3It's great to see more attention coming to it. Some other libraries worth keeping an eye on:
https://www.phlex.fun - Joel shipped this a few months ago ... it's very similar to Rux except it uses Ruby classes to achieve a similar effect. What's particularly interesting about Joel's efforts is that he is very worried about speed and performance, so it's a very fast templating framework.
https://youtu.be/9-rqBLjr5Eo?t=560 - This is the best overview of what Phoenix is shipping for their HTML framework, which is called HeeX (most of the docs already assume you're "in the know" with Elixir). HeeX is nice (like Rux) in that you can use HTML tags to embed server-side rendered components in markup with tags like ``. Not sure about Rux, but HeeX can reason about HTML from within itself, which means it can validate the DOM and make technologies like LiveView possible (https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.html).
I'm hoping at some point in the future a "de facto" (or actual) standard for Rails view components come into being so we can have an HTML-aware templating layer in Rails and improve the ecosystem through more standard UI components.
Re: Rux: A JSX-inspired way to render view components in Ruby
#4Kind of interesting,i would like it if it had a cleaner fallback to a non JSX version. If you one day decide to not use rux ~~~ h('div.example', [ h('h1#heading', 'This is hyperscript'), h('h2', 'creating React.js markup'), h(AnotherComponent, {foo: 'bar'}, [ h('li', [ h('a', {href: 'http://whatever.com'}, 'One list item') ]), h('li', 'Another list item') ]) ]) ); ~~~
Re: Rux: A JSX-inspired way to render view components in Ruby
#5Re: Rux: A JSX-inspired way to render view components in Ruby
#6Re: Rux: A JSX-inspired way to render view components in Ruby
#7Kind of interesting,i would like it if it had a cleaner fallback to a non JSX version. If you one day decide to not use rux ~~~ h('div.example', [ h('h1#heading', 'This is hyperscript'), h('h2', 'creating React.js markup'), h(AnotherComponent, {foo: 'bar'}, [ h('li', [ h('a', {href: 'http://whatever.com'}, 'One list item') ]), h('li', 'Another list item') ]) ]) ); ~~~
This is an example
creating React markup
One list item
Another list item
would translate to something like this: ["div", {"class": "example"}, [
["h1", {"id": "heading"}, ["This is an example"]],
["h2", {}, ["creating React markup"]],
[AnotherComponent, {"foo": "bar"}, [
["li", {}, [
["a", {"href": "http://whatever.com"}, ["One list item"]],
],
["li", {}, [
"Another list item",
["hr", {}, []],
],
],
]
and that all Rux/JSX/hyperscript/whatever would compile down to thatRe: Rux: A JSX-inspired way to render view components in Ruby
#8Re: Rux: A JSX-inspired way to render view components in Ruby
#9Re: Rux: A JSX-inspired way to render view components in Ruby
#10Kind of interesting,i would like it if it had a cleaner fallback to a non JSX version. If you one day decide to not use rux ~~~ h('div.example', [ h('h1#heading', 'This is hyperscript'), h('h2', 'creating React.js markup'), h(AnotherComponent, {foo: 'bar'}, [ h('li', [ h('a', {href: 'http://whatever.com'}, 'One list item') ]), h('li', 'Another list item') ]) ]) ); ~~~
even simpler, I have always wished that JSX/JSX-alikes would serialize to something like a tuple like `(tag: string | Component, attributes: Record, children: List)`, so your example would start looking something like this: This is an example creating React markup One list item Another list item would translate to something like this: ["div", {"class": "example"}, [ ["h1", {"id": "heading"}, ["This is an example"]],…
Here's the JSON for a landing page written in my syntax: https://github.com/jazzyjackson/lookalive/blob/master/docs/i...
In another project I use it extensively to mix javascript in with the object syntax as you would with JSX: https://github.com/lookalive-software/geodesy/blob/newfocus/...
The implementation is fairly simple, given JSON returns an HTML string.
https://github.com/lookalive-software/elementary/blob/master...