These are chat archives for opal/opal

10th
May 2016
Mitch VanDuyn
@catmando
May 10 2016 14:53
@fkchang @elia @jgaskins @ajjahn @wied03 any ideas on the above? Sorry to be a pest, I have this presentation tomorrow night, and I was hoping to clean up one of the gems before then...
Elia Schito
@elia
May 10 2016 14:56
@catmando in opal-rails data is transformed to json and then back to ruby so its all primitive types
Brady Wied
@wied03
May 10 2016 14:56
@catmando - if it's React, why not pass in via props ?
Mitch VanDuyn
@catmando
May 10 2016 14:58
@wied03 its for an API key that you have to have on the client and server. The key is set in an config file on the server, so it would just be nice to have the gem get it down to the client without any extra coding.
Specifically this is to enable pusher.com integration with reactive-record FYI
Brady Wied
@wied03
May 10 2016 15:00
well, if you're OK using what could be considered a hack by modern Sprockets standards, you could create a config class that's in an ERB file
and ERB would drop in the API key, sprockets would compile it and you'd have a constant in an Opal class
Mitch VanDuyn
@catmando
May 10 2016 15:00
yeah that is where I was going. Can I assume ERB is there if sprockets is there?
Brady Wied
@wied03
May 10 2016 15:01
historically yes, but they are discouraging that I think
might be better to create a Rake task that code gens that for you
Mitch VanDuyn
@catmando
May 10 2016 15:01
soooo what is the proposed alternative, I guess that is what I am asking
Brady Wied
@wied03
May 10 2016 15:01
the rails js routes project hooks that in with their railtie such that it generates an asset fairly automatically
Mitch VanDuyn
@catmando
May 10 2016 15:01
but then the user has to remember to run this rake task when ever they change the config
Elia Schito
@elia
May 10 2016 15:02
@catmando also dumping stuff as json in data-attributes or meta tags
Brady Wied
@wied03
May 10 2016 15:02
@elia - he wants it to be automatic without extra coding
Mitch VanDuyn
@catmando
May 10 2016 15:02
yeah - I know how to send values between client and server :-)
but @wied03 has it right.
currently I would do something like this in the gem
Elia Schito
@elia
May 10 2016 15:04
sorry, kinda skimmed the question and thrown stuff at the wall in the hope something sticked :smile:
Brady Wied
@wied03
May 10 2016 15:04
@catmando - maybe https://github.com/railsware/js-routes has a good way they do that
Mitch VanDuyn
@catmando
May 10 2016 15:05
#config.rb.erb
module MyGemConfig
  def value
     '<%= MyGemConfig.value %>'
  end
end
looks like ERB is the way to go.. (I was just kidding @elia appreciate the help always!)
Elia Schito
@elia
May 10 2016 15:07
(no worries :wink:)
Brady Wied
@wied03
May 10 2016 15:09
You could also use gon to set some of that in a JS global and then pick it up that way
Mitch VanDuyn
@catmando
May 10 2016 15:15
gon?
Elia Schito
@elia
May 10 2016 15:21
well gon does more or less the same we do in opal-rails: https://github.com/opal/opal-rails#as-a-template
note the @post ivar being available on both sides
Mitch VanDuyn
@catmando
May 10 2016 21:57
@elia / @wied03 - thanks for the help... I tried using the ERB in the gem, and it works, BUT, when you change the config file in rails and restart, it does not take the change in the config... Is there some way I can force the file to get blown away on server start?
Elia Schito
@elia
May 10 2016 22:06
@catmando you can use sprockets directive to link that file to another so its refreshed whenever the first one is
which version of sprockets are you running?
Mitch VanDuyn
@catmando
May 10 2016 22:07
3.0?
yes
this should do