These are chat archives for opal/opal

Mar 2017
Bernhard Weichel
Mar 04 2017 10:20

@fkchang @meh @elia Regarding Opal Hash vs. JS object: I always stuggle and hack around this issue.

the bridge has two directions:

  1. getting an Object from JS and properly handle in Opal
  2. having an Opal hash and properly handle it in JS

I feel that the bridge should have clear entry points. for example I would really prefer if e.g. Hash has a to_JS which returns a JS object and can be passed to 3rd party JS libraries. And I would not consider that {a:1, b:2}.to_js yields a proper Opal object. It yields a JS object. I don't think that to_n provides this at the moment. I observe somtimes traces of Opal methods in the result.

I recently had the trouble when I tried to use neatjson.js. Eventually I ended up going via JSON to get a cleanJS object.

 outputjs = %x{neatjson(JSON.parse(JSON.stringify(#{object.to_n})), #{opts.to_n})}
Guillaume Grossetie
Mar 04 2017 13:51
I'm using this function in a wrapper API to convert from plain JSON to Opal.hash:
var toHash = function (object) {
  if (object && !object.smap) {
    return Opal.hash(object);
  return object;
-var options = Opal.hash({attributes: 'icons=font@ data-uri!'});
+var options = {attributes: 'icons=font@ data-uri!'};
var doc = asciidoctor.load('== Test', options);
This is at best "syntactic sugar" but at leastOpal.hash is hidden :smile:
Elia Schito
Mar 04 2017 21:27
@/all having a look at opal-rspec-rails right now
I fear it's yak-shaving time :D
Elia Schito
Mar 04 2017 23:21
@catmando @jgaskins just pushed some changes that should have fixed the regexp error
do you mainly use it from the browser or from the terminal?
Mitch VanDuyn
Mar 04 2017 23:22
Both. Terminal for debug
Whoops browser for debug, terminal for CI
Elia Schito
Mar 04 2017 23:28
for now I only checked browser