These are chat archives for opal/opal

30th
Sep 2016
Mitch VanDuyn
@catmando
Sep 30 2016 03:44
anybody know how to convert some arbitrary js object (that came from JSON but is already converted to nested arrays + hashes.
something nicer than
JSON.parse(`JSON.stringify(x)`)
which seems to work but...
Elia Schito
@elia
Sep 30 2016 10:39
@catmando Native(x) should work, but I guess the latest PR by @jgaskins applies here
Mitch VanDuyn
@catmando
Sep 30 2016 13:59
@elia - so if I do Native(x) the result will act just like a hash?
Mitch VanDuyn
@catmando
Sep 30 2016 14:08
seems not: This
JSON.parse(`JSON.stringify(data)`)
# does not act the same as 
Native(data)
but as far as the PR goes I don't think its a big deal... I can use the above work around, is a pretty limited case
Mitch VanDuyn
@catmando
Sep 30 2016 14:20
The specific problem I run into is I am not seeing how to do this:
foo.merge(Native(data))
I get no implicit conversion of native object to a hash,
when I try to do a to_h on Native(data) it returns nil.
Mitch VanDuyn
@catmando
Sep 30 2016 15:52
has anybody thought of putting in some compiler switch that would allow you to insert debugging hoopla into every method, block etc... Some kind of directive or something so you could build fancy trace routines....
Elia Schito
@elia
Sep 30 2016 15:53
you're right, Native will convert the array elements and give an Array but not the object to Hash
@catmando about tracing, I think @iliabylich can tell you if it's feasible
Mitch VanDuyn
@catmando
Sep 30 2016 16:11
@iliabylich what do you think? some way to have a compiler switch that would generate an extra call at the beginning (easier I think) and end (maybe harder) of every proc/block method.
This message was deleted
Elia Schito
@elia
Sep 30 2016 16:12
@catmando already tried lookig for a native JS tracing util?
Ilya Bylich
@iliabylich
Sep 30 2016 16:13
@catmando Could you explain how do you plan to use those extra calls?
Mitch VanDuyn
@catmando
Sep 30 2016 16:13
@elia - yes... my development process looks like this:
write code and tests
double size of code with puts statements
fix
remove puts statements
release
repeat
Ilya Bylich
@iliabylich
Sep 30 2016 16:13
Like m1 { m2 } = 'started m1' -> 'started m2' -> 'finished m2' -> 'finished m1'?
Mitch VanDuyn
@catmando
Sep 30 2016 16:14
@iliabylich
yeah so this would call some globally defined method that would have lots of fun info
that you could then build a nice trace (and break) utility
it would run slowly of course, but so nice
Ilya Bylich
@iliabylich
Sep 30 2016 16:16
it's definitely doable. you can do it yourself if you are on the latest master
Mitch VanDuyn
@catmando
Sep 30 2016 16:16
yes I will try, if I can just have some hints about where it would be done...
but not until I get this current synchromesh project finished :-)
Ilya Bylich
@iliabylich
Sep 30 2016 16:17
opal/master supports adding custom ast rewriters
(start feeling that I propose it to everyone as a silver bullet :smile:)
Elia Schito
@elia
Sep 30 2016 16:18
when you have a hammer… :hammer:
Ilya Bylich
@iliabylich
Sep 30 2016 16:19
@catmando you can rewrite ast locally using your own rewriter. as a result you can inject ANY js to your code
https://github.com/opal/opal/blob/master/lib/opal/rewriters/opal_engine_check.rb <-- this is how Opal handles if RUBY_ENGINE == 'opal'
Mitch VanDuyn
@catmando
Sep 30 2016 16:21
@iliabylich - yeah thanks for the reminder... I remember you mentioned that about another topic a few months ago, and I thought HEY just what I need!
Don't know if you guys know that I do this for testing:
I have methods like this:
isomorphic do
  # code in here will be shipped to client for testing
  # and also run on server
end
so I can do this:
    isomorphic do
      TestModel.class_eval do
        scope :with_args, ->(match, match2) { where(test_attribute: match) }
      end
    end
So TestModel both on client and server now has the "with_args" scope
but its not perfect
and I actually thought of doing it all in reverse: Run the opal compiler on across the specs, and have it extract out isomorphic blocks, which are then fed to the normal compiler.
Something like that...