These are chat archives for opal/opal

27th
Apr 2015
Elia Schito
@elia
Apr 27 2015 00:10
@bwl21 https://github.com/opal/opal/blob/master/CHANGELOG.md it's a super micro release
Vais Salikhov
@vais
Apr 27 2015 10:09
@meh @fkchang the fix for #457 is on the opal master branch :)
Jared White
@jaredcwhite
Apr 27 2015 14:59
@meh I'd love to try out your fix for Promise#always -- however I can't seem to run anything on the latest Opal master. I had updated another project to master a few days ago, and run into a huge issue and figured maybe I was doing something wrong and reverted, but now I just updated a simple test project and ran into the same issue.
[Error] NameError: uninitialized constant Object::Document
(anonymous function) (kernel.js, line 1137)
$const_missing (module.js, line 329)
get (runtime.js, line 75)
(anonymous function) (index, line 214)
global code (index, line 246)
The issue seems to be that a bunch of extra library files (the opal-jquery stuff for example), as well as my own asset files, simply aren't being loaded. Maybe a Sprockets issue?
Sorry -- I misspoke -- the compiled JS is loaded into the browser, but it's not accessible in the runtime context. For example, document.js is loaded from opal-jquery, but if I go to the console and type "Opal.Document" it is undefined.
@adambeynon @fkchang BTW, I'm going to be sending out the next issue of the Opalist newsletter on Wednesday, so if you have any content/links you'd like me to include let me know in the next day or so. Thanks!
Nathan Hopkins
@hopsoft
Apr 27 2015 22:09
can someone demonstrate how to access a method on a global object. i'm using vue.js & would like to do this from opal. note Vue is a global.
  Vue.directive("html-with-newlines", function (value) {
    this.el.innerHTML = String(value).replace(/\n/g, '<br>');
  });
Elia Schito
@elia
Apr 27 2015 22:10
@hopsoft Easiest way is probably through Native()
Nathan Hopkins
@hopsoft
Apr 27 2015 22:12
I'm trying Native, but am getting: Uncaught NoMethodError: undefined method `directive' for #<Proc:0x59>
Elia Schito
@elia
Apr 27 2015 22:12
Vue = Native(`Vue`)
Vue.directive('html-with-newlines', -> value { Native(`this`)[:el].innerHTML = String(value).gsub("\n", '<br/>')}
I see, it's a known problem
Proc == js Function
so whenever Native tries to guess if an object is a Native or an opal object gets confused if the object lives in both worlds
Nathan Hopkins
@hopsoft
Apr 27 2015 22:14
any workarounds?
other than backticks with js?
Elia Schito
@elia
Apr 27 2015 22:16
you can still wrap it manually:
class Vue < Struct.new(:native)
  def self.directive(selector, &block)
    `window.Vue.directive(selector, fuction(value) { #{block.call(value)} }`
  end
end
a great example of this technique is opal-jquery
@hopsoft if Native was viable you could have used $$ which is the equivalent of Native(`window`)
elia @elia is looking up vue.js
Elia Schito
@elia
Apr 27 2015 22:19
@meh wdyt of adding a second option on Kernel#Native to force wrapping instead of guessing if it's native?
meh.
@meh
Apr 27 2015 22:20
@elia how do you mean?
Elia Schito
@elia
Apr 27 2015 22:20
a function isn't recognized as Native bc it's bridged to Proc
same goes with Array and all bridged objects
…be glad to be proven wrong tho
Nathan Hopkins
@hopsoft
Apr 27 2015 22:22
@elia thanks for the help
Elia Schito
@elia
Apr 27 2015 22:23
@meh e.g.:
> opal -rnative -e 'p Native(`[{},{a:1}]`).class'
Array
@hopsoft anytime
meh.
@meh
Apr 27 2015 22:24
@elia I don't like the idea, the point of Native is to only make an Opal object what is not
Elia Schito
@elia
Apr 27 2015 22:25
yeah, not attached to the solution, but I hear about the issue all the time
meh.
@meh
Apr 27 2015 22:25
I think Native::Array does something for that, but I might be remembering wrong, wouldn't be hard to check in Native if it's an Array and make everything inside a Native
Elia Schito
@elia
Apr 27 2015 22:25
it needs some special treatment for bridged objects as you don't really know if their contents are opal or native
that also prevents any constructor from being wrapped directly as it's recognized as a Proc