These are chat archives for opal/opal

22nd
Jun 2016
meh.
@meh
Jun 22 2016 00:26
catmando, performance wise? there isn't a difference from some benchmarks I made ages ago, and I doubt things got worse
Jamie Gaskins
@jgaskins
Jun 22 2016 02:25

Yeah, it's not like in MRI where method lookup is very expensive — it uses a method cache internally, but that's unnecessary in a JS VM. My guess as to his motive is that metaprogramming is fun. ;-)

@catmando In your example, div points to the same function in the VM as method_missing, wired up at compile time. The only extra cost is inside method_missing, which is probably reduced to almost 0 after a couple executions of it when the JIT gets ahold of it. Would be best not to conjecture and run benchmarks instead. :-)

Jikku Jose
@JikkuJose
Jun 22 2016 18:56

@fkchang Hey, thanks for replying! This is my setup: https://github.com/JikkuJose/react-lab/tree/feature-opal_support

I am trying to import a simple Ruby class to a typical React project.

This is the Ruby file: https://github.com/JikkuJose/react-lab/blob/feature-opal_support/src/js/app/para.rb
This is how I am hoping to us it: https://github.com/JikkuJose/react-lab/blob/feature-opal_support/src/js/app.jsx#L9

Note: Now, I am referring to the jsx file instead of the .rb file. But didn't work when I was using it.

Quick question: Opal compiles to es5?
Is there any equivalent for specifying the Ruby class as the one thats being exported? I think everything is getting compiled well, but I am unable to refer to the class I am creating.
Ilya Bylich
@iliabylich
Jun 22 2016 19:14
To get a Ruby class form JS you need to call Opal.YourClass. To create its instance use .$new(), to call your own method call .$your_method(). For your code it should be Opal.Paragraph.$new().$text().
No, opal doesn't support ES5
And ideally you should use your Ruby classes from your Ruby code, it can be really painful to use compiled JS directly (talking about things like Ruby blocks).
Jikku Jose
@JikkuJose
Jun 22 2016 19:29
Wow! Thats great help!

@iliabylich I was able to use the Ruby class like you mentioned. I understand its not very pretty, but I was just trying to see if it was possible. It definitely looks awful to write Opal.Paragraph.$new().$text(); but the capability to do Ruby along side JS feels cool. Certainly not for production, but to see the value of webpack.

Loud Thought: If Ruby classes could have been addressed like normal es6 classes this would have been a great way to use Opal along side, so that we could code in either Ruby or es6.

Dino Maric
@dixpac
Jun 22 2016 20:12
Hi all! One quick question I'm new to Opal....can I use any ruby gems with opal...i want to require "browser" gem in open file(app/application.rb)...is that possible ?
Jamie Gaskins
@jgaskins
Jun 22 2016 20:16
@dixpac It might work. If you run this in Ruby, do you get any errors?
require 'opal'
require 'browser' # This may not be necessary
Opal.use_gem 'browser'
Dino Maric
@dixpac
Jun 22 2016 20:19
hey when i run it i get this
Screen Shot 2016-06-22 at 22.19.12.png
Jamie Gaskins
@jgaskins
Jun 22 2016 20:20
Sorry, I mean run that on MRI
And then in your Opal app:
require 'opal'
require 'browser'
Dino Maric
@dixpac
Jun 22 2016 20:23
yap...work fine using MRI
but when I rack it up :) ....I it is not working
Jamie Gaskins
@jgaskins
Jun 22 2016 20:25
What's the error?
Dino Maric
@dixpac
Jun 22 2016 20:26
can you see screenshot i attached 3 comments up ?
when i require gems like this
require 'opal' Opal.use_gem 'browser'
no sprockets error but
Uncaught NoMethodError: undefined method `use_gem' for undefined
in console
Jamie Gaskins
@jgaskins
Jun 22 2016 20:30
You don't run use_gem on the client app
Run that on the server. Run the second code block in your client app.
Dino Maric
@dixpac
Jun 22 2016 20:31
yea...when I run second I get sprockets error :(
Jamie Gaskins
@jgaskins
Jun 22 2016 20:32
Same:
Sprockets::FileNotFound at /
couldn't find file 'uri' with type 'application/javascript'
Opal doesn't support the uri library yet.
But that's a different error than you got
Or at least a different one than you posted
Dino Maric
@dixpac
Jun 22 2016 20:33
i get this error
couldn't find file 'browser' with type 'application/javascript'
looks like similar kind of error to me...:)
Jamie Gaskins
@jgaskins
Jun 22 2016 20:34
It's the same error, but different library. Yours means that your server process hasn't run Opal.use_gem 'browser'. If you added it, you need to restart your server.
Christian Käser
@dfyx
Jun 22 2016 20:35
Is there any (good) documentation for the Browser::Canvas class? I've started playing around with it but its API appears to be quite different from the native one
Christian Käser
@dfyx
Jun 22 2016 20:52
Or at least a usage example? (paging @meh )