Current Status of Opal Native

80 views
Skip to first unread message

Dennis Prochniak

unread,
Jan 21, 2015, 3:27:12 AM1/21/15
to opa...@googlegroups.com
More than one year ago I asked about the status of Opal Native (https://github.com/opal/opal/issues/233) I received a few interesting replies from the core members. The issue was closed 2 months later with 'things have moved on'

Today I gave again Opal a try with non-positive results.

Here is the code for reference:
require 'opal'
require 'native'
require 'jquery'
Window = Native(`window`)
JQuery = Native(`window.jQuery`) //yes I know about opal-jquery, this is only for demonstration purposes
Window.jQuery('body').append('<h1>hello world from opal</h1>')
JQuery('body').append('<h1>hello world from opal</h1>')



I would like to ask whether Opal is ready for seamless JavaScript interaction yet? If not, when is it planned to be.                                           

Elia Schito

unread,
Jan 28, 2015, 5:00:16 AM1/28/15
to opa...@googlegroups.com
Dear Dennis,

the following works, there's a known problem with Native wrapping when applied to bridged classes (String, Array, Proc, …). That's something we'll have to address.

require 'opal'
require 'native'

Window = Native(`window`)
JQuery = Native(`window.jQuery`) # PS. the comment was in JS format (//)
Window.jQuery('body').append('<h1>hello world from opal</h1>')
Native(JQuery['body']).append('<h1>hello world from opal</h1>')

The problem with the original code is that JQuery (the constant) is a Proc, if you wanted to have JQuery as a method you must define it this way:

JQuery = Native(`window.jQuery`)
def JQuery(selector)
  JQuery.(selector)
end

That's how Ruby works, nothing specific to Opal.

About the issue you linked I suggest to check who the core members are, we're more than open to contribution and constructive criticism.


Elia

📢 twitter/elia 
☕️ github/elia 

--
You received this message because you are subscribed to the Google Groups "opalrb" group.
To unsubscribe from this group and stop receiving emails from it, send an email to opalrb+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages