Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to reuse a JavaScriptFunction to call from ruby back to javascript #228

Open
xrl opened this issue Jan 11, 2022 · 3 comments
Open

Comments

@xrl
Copy link

xrl commented Jan 11, 2022

I have attached a ruby block to my js context in order to power a callback mechanism. It should go ruby -> js -> ruby -> js (and maybe a few more times after that). My code looks something like:

      subject.register_helper('alsowith') do |this, context, block|
        context["fn"]
      end

where context looks like this in a debugger:

0> context
=> {"name"=>"alsowith", "hash"=>{}, "fn"=>#<MiniRacer::JavaScriptFunction:0x00007fd20c0a3620>, "inverse"=>#<MiniRacer::JavaScriptFunction:0x00007fd20c0a34e0>, "data"=>{"root"=>{"weather"=>{"summary"=>"sunny"}}}}

Unfortunately I can't use the "fn" key's value, a JavaScriptFunction appears to be an empty class and not invocable. I was expecting something like context["fn"].call(123) so I could keep going.

@gi
Copy link

gi commented Feb 3, 2022

@xrl This looks like it's a duplicate of #225.

@gi
Copy link

gi commented Feb 3, 2022

@xrl If you are doing something with Handlebars, I updated Tilt::Handlebars with the new Handlebars::Engine which uses MiniRacer instead of the defunct therubyracer.

@pswami
Copy link

pswami commented Nov 4, 2022

Been trying to figure out how to call context["fn"] as @xrl mentions above. @gi Any solution to this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants