These are chat archives for opal/opal

24th
Jun 2016
Yehonathan Sharvit
@viebel
Jun 24 2016 03:10
@catmando how did you do that?
Mitch VanDuyn
@catmando
Jun 24 2016 03:11
I think instructions are in opal readme
I'm about to go to bed. I'll po
.
Meantime look at SNOBOL gem. It's isomorphic. But I agree it's a bit tricky
Drew Hamlett
@drewhamlett
Jun 24 2016 11:59
Hello. I'm not able to see any output with Opal 0.9.4. I just started a project with Opal server and everything is getting compiled but the module isn't running
Opal.modules["application"] = function(Opal) {
  Opal.dynamic_require_severity = "error";
  var OPAL_CONFIG = { method_missing: true, arity_check: false, freezing: true, tainting: true };
  var self = Opal.top, $scope = Opal, nil = Opal.nil, $breaker = Opal.breaker, $slice = Opal.slice;

  Opal.add_stubs(['$require', '$puts']);
  self.$require("opal");
  return self.$puts("hello");
};
i see that but it's not running the code
I dont' remember having an issue with this before
Drew Hamlett
@drewhamlett
Jun 24 2016 12:04
    <script src="/assets/application.js"></script>
    <script>
      Opal.modules["application"](Opal)
    </script>
If it put that everything is working. so not sure what's happening
Elia Schito
@elia
Jun 24 2016 12:25
@drewhamlett sprockets compiles files only to modules, that's after 0.8 iirc, to allow require order to be respected
the solution you're using is correct, the official API is Opal.load('application')
I have a solution for that in the works but it's not released yet : )
Bernhard Weichel
@bwl21
Jun 24 2016 14:10
what is the best way to capture keyboard events. E.g. if one enters ctrl-R (or cmd-R) I would like to do a refresh in my application, not in the browser window,
tried to use
    Browser::EventSource.new '/events' do |es|
      es.on :message do |e|
        alert e.data
      end

      es.on :keydown do |e|
        alert "keydown #{e.data}"
      end
      es.on :customs: do |e|
        alert "custom #{e.data}"
      end
    end
Ilya Bylich
@iliabylich
Jun 24 2016 14:39
@bwl21 I think you are using a wrong class :smile:
EventSource is not for keyboard events, it's for server-side events
Jamie Gaskins
@jgaskins
Jun 24 2016 16:48
@bwl21 Assuming you're using opal-browser, you might be able to do it like this:
$window.on :keydown do |e|
  if (e.meta? || e.ctrl?) && e.code == 82 # Ctrl/Cmd + R
    e.prevent
    refresh_app
  end
end
refresh_app would be your own defined behavior
Bernhard Weichel
@bwl21
Jun 24 2016 18:01

@jgaskins: you brought me to the right track. Thanks. Eventually this code works:

    $window.on :keydown do |e|
      if (e.meta_key || e.ctrl_key) && (e.key_code == 82) # Ctrl/Cmd + R
        e.prevent
        render_previews();
      end
    end

Is there somwhere a documentation wehre I could have find this:
is $windowequivalent to Element.find(`window`) ? Where is this global set? How to avoid name conflicts with an application global named $window?

I found the name of e.meta_key etc. by debugger.