These are chat archives for opal/opal

28th
Jun 2016
Mehmet Beydogan
@beydogan
Jun 28 2016 11:31
This message was deleted
Mehmet Beydogan
@beydogan
Jun 28 2016 11:39

Hi, I'm using opal-rails and upgraded from 0.8.1 to 0.9.0.

I have a global variable defined js.

gon.events

On opal side, I access it by;

events = $$.gon.events

problem is; when using opal rails 0.9.0 it changes the structure of objects as following;

in 0.8.1;
8

in 0.9.0 or any version above 0.8.1
9

how can i fix this issue?

Ilya Bylich
@iliabylich
Jun 28 2016 14:23
@beydogan Could you try $$.gon.events.to_n ?
Mitch VanDuyn
@catmando
Jun 28 2016 21:09
I'm pretty sure the answer is going to come back to be use eval
I'm looking at the js code generated by opal, and I see something like $scope.get('Foo') that seems to lookup component Foo. Is there a reasonable way to use this to look up 'Foo' in the current module/class lexical hierarchy?
instead of just rewriting a method?
Jamie Gaskins
@jgaskins
Jun 28 2016 23:53

I don't think you can get lexical scope programmatically, because that's defined in the parser. If you rewrote that code instead like this:

module Foo
end

class Foo::Whack
end

module Foo::Bar
end

class Foo::Bar::Baz
  def self.test(s)
    const_get s.to_s
  end
  def self.test1
    test(Whack)
  end
end

Both of your test methods would fail, but your lookup method would still work.