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
ryanprior
I used Opal for a project where I already had a software library in Ruby, and wanted to create a web app to make it easier to consume directly. It would not have been a huge effort to reimplement the library in Javascript, or to put up a Ruby backend server and have the front-end written in Javascript to consume it, but completing the project with Opal and the Inesita framework only took a couple days, including learning time having never used either before (but lots of Ruby otherwise.) If I were in a similar situation again, I would not hesitate to give Inesita another crack.
ryanprior
The completed web app in question is here: https://cyberark.github.io/conjur-policy-generator/