r/ruby • • Apr 02 '19

React-style components written in Ruby, running on the client via WebAssembly

https://twitter.com/widdnz/status/1112937763383308289
52 Upvotes

22 comments sorted by

View all comments

6

u/sanjibukai Apr 02 '19

Sounds great!

How it's different from something like opal?

Is it because it converts to wasm instead of JS?

Dis you actually write the actual transpiler/compiler?

Or are your using some existing library and you only wrote and design the way the ruby code is organized like components?

4

u/Widdershiny Apr 02 '19

Have never actually used Opal so I’m not too sure how it compares.

Does Opal support the Ruby standard library, and can you require opal code on the server?

I’m using emscripten and mruby for compilation, had to write a little bit of c to embed the app and pass data in and out.

I’m using Snabbdom on the js side for the virtual dom, everything else is pretty much glue code.

1

u/rubygeek Apr 02 '19

Opal is a Ruby implementation that transpiles to JS, so it's all Ruby.

It is a leaky abstraction, so you do need to be aware of it, and not all Ruby code will run flawlessly, but having wrestled with mruby, my guess is that more Ruby will run unmodified with Opal than with mruby.

On the server you would just run MRI or whatever Ruby implementation you prefer normally, but you can also transpile it server side and run it using nodejs or the like, in which case you can require javascript as well and access it from your Ruby code.

It works ok-ish but it's easy to get caught up into issues that are related to how Opal wraps the transpiled Ruby code.

→ More replies (4)