These are chat archives for opal/opal

27th
May 2015
Francesco 'makevoid' Canessa
@makevoid
May 27 2015 11:12
@RickCarlino do you plan to record a video of the session? that would be cool
Rick Carlino
@RickCarlino
May 27 2015 12:26
@makevoid In the past, we've done video streams. I can make that happen.
Francesco 'makevoid' Canessa
@makevoid
May 27 2015 13:39
I think it will be useful for rubysts that want to start playing with opal, there are not many videos out there
CJ Lazell
@cj
May 27 2015 17:37
so I'm trying to find out where it appends the required js to the compiled result as I need to append code https://github.com/opal/opal/blob/master/lib/opal/sprockets/processor.rb#L43-L46
the result.to_s is still just the single file and doesn't include all the files js it requires
Mitch VanDuyn
@catmando
May 27 2015 17:51
arghh! I need to define a javascript var at the global level from within opal. I want to do something like this:
var Foo = some_func_call()
where Foo is the result of a function call.
i.e.
Jared White
@jaredcwhite
May 27 2015 17:53
@catmando All global JS vars are essentially properties on window. So you can simply do window.Foo = some_func_call()
Mitch VanDuyn
@catmando
May 27 2015 17:53
yeah
but I Foo itself is a variable
i.e. "Foo" is the result of a function call
do I have to use javascript eval?
Jared White
@jaredcwhite
May 27 2015 17:55
Not following
at which ever point you have a variable that you want to assign to the global level (lets' call it local_var, in backticks you would write JS code:
window.globalVar = local_var
Mitch VanDuyn
@catmando
May 27 2015 17:57
no like this
window[name_to_be_defined] = something_else
Jared White
@jaredcwhite
May 27 2015 17:58
what you just wrote will work actually
Mitch VanDuyn
@catmando
May 27 2015 17:59
nope tried that
Jared White
@jaredcwhite
May 27 2015 17:59
I just tried it in my JS console:
foo = "myVar"
< "myVar"
window[foo] = "something"
< "something"
window.myVar
< "something"
Mitch VanDuyn
@catmando
May 27 2015 18:01
yes lovely... I know how to do it JS
I am trying to do it ruby
Jared White
@jaredcwhite
May 27 2015 18:03
You mean an Opal-context global var? Hmm, not sure about that. I always encapsulate "global" variables instead of a Ruby class or a module.
CJ Lazell
@cj
May 27 2015 18:05
hopefully this might help understand what I'm trying to do (sorry about the non dry code, just trying to get it working) https://gist.github.com/cj/11a226a6df25c3a49e41#file-opal-rb-L22 I'm trying to override the compile method to append some javascript. The issue is it needs all the required files included with the compiled js, but when it hits compile it's just the single file.... this hack works but there must be a better way to tell/trigger once all files are joined
Mitch VanDuyn
@catmando
May 27 2015 18:05
@jaredcwhite Yes, but this is for a special case (communicating to React JS via Rails-React)
CJ Lazell
@cj
May 27 2015 18:07
I tried wrapping it in a simple typeof check but then the code block never gets executed
Elia Schito
@elia
May 27 2015 18:08
@catmando with native loaded this should work
Native(`window`)[some_key] = whatever
CJ Lazell
@cj
May 27 2015 18:09
I can't seem to find which opal is adding the compiled js for all the require 'foo' in a certain file
where*
Mitch VanDuyn
@catmando
May 27 2015 18:13
@elia - thank you kind sir. Almost there with a very nice opal-react-rails demo!
Mitch VanDuyn
@catmando
May 27 2015 18:29
@elia - we are just looking at this... (works) but can you explain exactly what Native() does?
Elia Schito
@elia
May 27 2015 19:03
@catmando really briefly native creates a ruby object with a @native ivar that contains the native object, then uses method missing to call native methods + #[] and #[]= for properties reading/setting
CJ Lazell
@cj
May 27 2015 19:08
is there anyway to execute code after Opal.modules["wedge"] has been triggered ?
I'm trying add code on compile that only gets executed once the file has been loaded including all it's requires