These are chat archives for opal/opal

1st
Mar 2018
Billy.Zheng
@zw963
Mar 01 2018 13:31
@elia , emacs web-mode maintainer ask me, could you ask Opal maintainer to put on the website a note saying that emacs (with web-mode) is compatible ?
what do you think? thanks
I think this maybe the first editor which support text/ruby script tag editor ?
Simon George
@sfcgeorge
Mar 01 2018 13:48
@zw963 Sounds good for the Awesome Opal / Libraries page http://opalrb.com/libraries/

How does one get the native JS object out of an Opal object? Aka, I want to create a Date in Opal then pass it into some backticks JS, but I don't think this is right:

date = Date.today
`someJsThing({ defaultDate: #{date} })`

I don't see any .to_n .to_native .native or anything like that.

Elia Schito
@elia
Mar 01 2018 13:55

@sfcgeorge looks like it inside the @date ivar, https://github.com/opal/opal/blob/9b53895088dddfb5048d2cbb6196c186a6a48bd9/stdlib/date.rb#L102, which should definitely be returned by #to_n, can you send a PR for that?

#to_n should be added to native.rb in this area: https://github.com/opal/opal/blob/9b53895088dddfb5048d2cbb6196c186a6a48bd9/stdlib/native.rb#L499

Simon George
@sfcgeorge
Mar 01 2018 13:57

Looking at the compiled code it comes out with a to_s, whereas I want the native JS object inside

someJsThing({ defaultDate: date.$to_s() })

I see I can do it via the Opal JS API like this:

Opal.Date.$today().date

@elia So you're saying that there should be a to_n that does that?

Elia Schito
@elia
Mar 01 2018 13:58
@sfcgeorge yeah, there should be, but I think there's not, anyway in the meantime you can do:
`someJsThing({ defaultDate: #{date.JS[:date]} })`
Simon George
@sfcgeorge
Mar 01 2018 14:00

Ooooh that .JS thing is what I was looking for, I thought I'd seen something like that but it's not in the Native docs as that's going the other way round.
Or I could get the ivar I guess,

Date.today.instance_variable_get('@date')

So @elia would you like me to add a to_n in Date like this?

class Date
  def to_n
    @date
  end
end
Elia Schito
@elia
Mar 01 2018 14:01
@sfcgeorge yes, but thinking again the right place is stdlib/date.rb, native.rb should contain definitions only for the corelib classes
Simon George
@sfcgeorge
Mar 01 2018 14:02
Okay, I think that makes sense. Although maybe all the to_ns in native.rb should be in their respective corelib files? Doesn't really matter, I'm happy to put this in stdlib/date.rb to follow current convention.
REALLY what I'm saying here is that the JS date API is so horrible and Ruby is so nice and Opal is so amazing that I'd rather do it in Opal even if there is the odd minor snag. Opal is 10x better than I ever thought possible.
Elia Schito
@elia
Mar 01 2018 14:04
:smile: :green_heart:
Barrie Hadfield
@barriehadfield
Mar 01 2018 15:26
hello - does anyone know if there is a way to get OpalSprockets to not create source maps?
Barrie Hadfield
@barriehadfield
Mar 01 2018 15:28
Thank you so much @elia I did look but did not find it!
Elia Schito
@elia
Mar 01 2018 15:29
@barriehadfield maybe it's worth adding a note to the README
Barrie Hadfield
@barriehadfield
Mar 01 2018 15:30
yes, I will create a PR
Elia Schito
@elia
Mar 01 2018 15:30
:thumbsup: :smile:
Barrie Hadfield
@barriehadfield
Mar 01 2018 15:45
done @elia - many thanks
Simon George
@sfcgeorge
Mar 01 2018 16:19
@elia And on that vein, I like sourcemaps for my code, but there are loads of sourcemaps for Opal core stuff. So is there a way to disable sourcemaps just for Opal corelib stuff?
@elia And I will try to send a Date#to_n PR after work :)
Elia Schito
@elia
Mar 01 2018 16:22

@sfcgeorge it's on my checklist, but never had the time to tackle it inside opal itself, usually inside rails I add this file:

opal-collapsed.js.erb

//= depend_on opal
<%= Rails.application.assets['opal'].to_s %>

And I require it instead of opal inside my application files

Simon George
@sfcgeorge
Mar 01 2018 16:23
@elia Ooh that's interesting, I'll give it a try thank you :)
Forrest Chang
@fkchang
Mar 01 2018 16:30
@elia it'd be nice to be able to turn on/off source maps on the fly, maybe an end point just for that
Elia Schito
@elia
Mar 01 2018 16:34
@fkchang I think it can be done, IIRC it's just an http header, what's the use case specifically?
Simon George
@sfcgeorge
Mar 01 2018 16:38
@fkchang Chrome > Inspector > [kebab menu] > Settings > Sources > untick Enable JavaScript Source Maps.
Forrest Chang
@fkchang
Mar 01 2018 16:59
@elia I was thinking that I only need source maps when debugging, but if your opal-collapses.js.erb trick makes it quick to load, then I'd just keep them
@sfcgeorge that could work - I should try it when I get a chance, I was thinking of something that flipped Opal::Config.source_map_enabled = false|true on the server originally
G. Gibson
@mistergibson
Mar 01 2018 19:25
I still think opal needs a DateTime class
Elia Schito
@elia
Mar 01 2018 19:49
@fkchang yes, the general case would be collapsing (i.e. kinda black-boxing) everything except application code