Opal.defn
works
ADVANCED_OPTIMIZATIONS
Opal.modules["corelib/module"].$class_variable_get = function() {};
mid_to_jsid
Hi I need an advice: I initialize the contoller of my app with
Document.ready.then do |ready|
uicontroller = Controller.new
%x{
window.zupfnoter=#{uicontroller};
}
end
In order to have a global access to the Controller -instance I assign it to window.zupfnoter
. The Controller produces SVG code in a worker which returns the SVG as a string. I would like to declare handlers in this string. I figured out the JS source code requird in the SVG code to access a method of an object stored in an instance variable of my controller:
onclick = %Q{onclick="zupfnoter.tune_preview_printer.$_clickabcnote(evt, '#{id}')"}
%x{
#{@root}.out_svg('<rect ' + #{onclick}' ...);
which eventually produces
<rect onclick="zupfnoter.tune_preview_printer.$_clickabcnote(evt, '_note_436_438_')"></rect>
even if if works, I am not sure if this is the most elegant and robust approach:
It depends on the global variable (zupfnoter
). I would prefer to access the instance of the controller via something like Opal.top.uicontroller
such that I do not need the global variable.
It depends on the internals of the opal compiler. I would like to get the javascript name of the handler without knowledge of the internals how Ruby code is converted to javascript.
it should be something like
onclick = %Q{onclick="#{JS.methodcall(uicontroller.tune_preview_printer._clickabcnote)}(evt, '#{id}')"}
Opal.top.…
is still a global as you pointed out, so it would be any Opal class.
@/all I'd like to thank @catmando for providing stickers for the codemotion conference that's being held in milan this week :tada: :tada: :tada: :tada: :tada: Thanks Mitch!!!
If you're participating to a conference and want some stickers to promote Opal ping me and we'll try to provide you some