to update the state of my JavaScript (ReactJs) app inside my WebDialog, I registered a function window.setState(items) that handles the update of the current state. I’ve registered a callback to reload which executes this method:
@dlg.add_action_callback('reload') do |dialog, _value|
puts 'reload cb'
@journal.reload
command = 'window.setState(' + @journal.items.values.to_json + ')'
puts command
dialog.execute_script command
end
I also have a separate ruby method, which I use to trigger the reload from somewhere in my plugin (or console). It’s essentially the same.
Now when my callback is executed, it puts the command in the console, and calls the JS function, but it returns early, but I’m not sure what is going on (debugging the Webdialog is a pain in the ass). When I call my update method, it prints the exact same command to the console, but does everything it’s supposed to do, without an error.
Seems weird. Perhaps the block parameter dialog is not right ?
What platform Mac or PC ?
What browser version of Safari or MSIE ?
What SketchUp version ?
Does this work any better from inside the callback block (which I think gets converted to a Proc object.) ?
Ie, change the do & end, to { and }. They create blocks with different visibility.
Your do block may not “see” the @journal ?
Ok, I’ve been away from plugins for a while, but I still look at the forum every so often.
Try and wrap your callbacks from js => ruby in setTimeout calls. I recall some behavior differences (between Windows and OSX) as to what blocks what and where. You may need a closure. Most of the time, the few milliseconds that a setTimeout takes isn’t an issue.
Also, re some comments in this thread, window is to js as Kernel is to Ruby. If a js function is declared globally, window.someFunction() is the same as someFunction(), assuming you’re in a ‘browser’ environment and no one has redefined window…