These are chat archives for opal/opal

25th
May 2015
Mitch VanDuyn
@catmando
May 25 2015 13:58

Could anybody help with a little problem I am having? I am working with the react.rb gem. Currently when you do a require, you say:
require 'react'
but this keeps causing all sorts of problems because of the name space collision with the react.js library.

I want to change things so that you say require 'opal-react' (like opal-jquery) but still use the React name space within opal to refer to the opal wrapper. (I assume this is okay with the opal team, if not then something like ruby-react would be fine)

This is a dumb question I think, but I am not seeing how this is done with opal-jquery.

THANKS IN ADVANCE!

Elia Schito
@elia
May 25 2015 14:05
@catmando you should consider them as normal ruby requires and actively forgot the special bound between module/class naming and file names that rails adds
also think of js files as native libs, the same way as you require a .so file in MRI
(not that that happens often, but the idea it's the same)
Mitch VanDuyn
@catmando
May 25 2015 14:09
@elia well, the problems I keep having is with using react.rb in rails... I am pretty sure its because of the specific name "react.rb". I worked around the first set of problems, but now am getting things working with rails-react, and I am back into the middle of these issues. I have no problems using other opal gems, so I am assuming I just need to change the name of react.rb to something else.
But I would like to keep it so that within the opal code you can still just use the Module "React".
Elia Schito
@elia
May 25 2015 14:10
@catmando just renaming the files and updating the requires should do the job
Mitch VanDuyn
@catmando
May 25 2015 14:10
I am pretty if I just change the whole gem to say "reactrb" and call the outer scope ReactRB things will work fine
But I would prefer if possible to be able to use React inside Opal while requiring 'opal-react'.
I think this is essentially what was done with opal-jquery as well.
Elia Schito
@elia
May 25 2015 14:12
@catmando have you tried it? it should work fineā€¦
let me know if you get any specific error
and remember that module namespace doesn't need to match filenames
Mitch VanDuyn
@catmando
May 25 2015 14:12
So you think if I just change the gem name to "opal-react" from "react.rb" things should work?
Elia Schito
@elia
May 25 2015 14:13
I don't think the problem is with the gem name at all
Mitch VanDuyn
@catmando
May 25 2015 14:13
OHHH I see... I also need to change the top level file from react.rb to opal-react.rb... got it.
:+1:
Mitch VanDuyn
@catmando
May 25 2015 14:16

so just change this to

if RUBY_ENGINE == 'opal'
  require "opal-react/top_level"
  require "opal-react/component"
  require "opal-react/element"
  require "opal-react/event"
  require "opal-react/version"
  require "opal-react/api"
  require "opal-react/validator"
else
  require "tilt"
  require "opal"
  require "react/version"
  require "opal-activesupport"
  require "react/ext/jsx_support"

  Opal.append_path File.expand_path('../', __FILE__).untaint
  Opal.append_path File.expand_path('../../vendor', __FILE__).untaint
end

and change lib/react.rb to lib/opal-react.rb
Is that right?

Elia Schito
@elia
May 25 2015 14:17
yes, and also rename lib/react to lib/opal-react
Mitch VanDuyn
@catmando
May 25 2015 14:29
OKAY! That worked... and hopefully that means I can now drop 'opal-react' into react-rails, and really have some fun!
@elia Thank You So Much!
Elia Schito
@elia
May 25 2015 14:29
anytime!
Mitch VanDuyn
@catmando
May 25 2015 17:52
@elia once the name was changed to opal-react, there was zero problems integrated with react-rails. Instant isomorphic rendering in ruby. I am proposing to react.rb's developer that we rename to opal-react. Is that okay?
Elia Schito
@elia
May 25 2015 20:28
@catmando sure it is
no need to ask anyway ;)
Elia Schito
@elia
May 25 2015 20:41
@catmando btw an example app with opal-react+react-rails+clearwater would be really cool
blog post/tut would be super :sparkles:
@catmando does this setup do server side rendering too?
Mitch VanDuyn
@catmando
May 25 2015 20:44
Ye'*
@elia yep just tried a small test, but seems to work fine, server and client. The react API in ruby reads beautifully, and react integrates so easily
Mitch VanDuyn
@catmando
May 25 2015 20:49
I expect to have some pages on our website converted by end of week.
Will also work on a to do demo