These are chat archives for opal/opal

4th
Mar 2017
Bernhard Weichel
@bwl21
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
@Mogztter
Mar 04 2017 13:51
I'm using this function in a wrapper API to convert from plain JSON to Opal.hash: https://github.com/asciidoctor/asciidoctor.js/blob/0866d3335699f728f0a9197f8f01c51ce92525cc/src/asciidoctor-core-api.js#L1-L6
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
@elia
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
@elia
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
@catmando
Mar 04 2017 23:22
Both. Terminal for debug
Whoops browser for debug, terminal for CI
Elia Schito
@elia
Mar 04 2017 23:28
for now I only checked browser