These are chat archives for opal/opal

Aug 2015
Gregory Clark
Aug 30 2015 03:47
The big question is.... Can Opal compile itself into JavaScript?
Bernhard Weichel
Aug 30 2015 07:19
@Qqwy wrt to event emitter: best is to implement a wrapper class for EventEmitter.
Adam Beynon
Aug 30 2015 07:19
@gregc of course! We provide opal/parser.js which is the gem compiled by itself
Bernhard Weichel
Aug 30 2015 07:54
@Qqwy It is similar to this (did not test it):
class EventEmitter

    def initialize()
           var EventEmitter = require('events').EventEmitter;
           var #{@radium} = new EventEmitter();  

    def on(event, &block)
       Native(@radium).on(event, block)

    def start
       setInterval(function() {
          #{@radium}.emit('radiation', 'GAMMA');
         }, 1000);

e =
e.on(:radiation) do |ray|
    puts ray

Forrest Chang
Aug 30 2015 09:53

@meh what's the right way to do this in paggio?

        Paggio.html! do |_|
          _.label({for: name}) {label}
          _.input.nbb({name: name, id: name, value: source, readonly: true})

I'm getting

<label for="number-editor-1526"> @a </label> <input class="nbb"> {"name"=>"number-editor-1526", "id"=>"number-editor-1526", "value"=>"a", "readonly"=>true} </input>
Qqwy / Wiebe-Marten
Aug 30 2015 19:14
@bwl21 Thank you very much for your help!
Indeed it would be nice to build a wrapper around it.
As for the code you've posted above: The Native(@radium).on(event, block) construction ought to work, but sadly it does not. The only way I managed to make it work was:
def event_emitter_register_event(object, eventname, &block)
    `#{object}.on(#{eventname}, block)`
This calls &block on the emission of the the 'eventname' event on the object. I would have expected the Native() element to work the same way, but alas, it did not
For now, when I need to listen to native Node events, I use this function. When creating my own, I use the ruby gem events which follows the Node EventEmitter syntax quite closely.
Bernhard Weichel
Aug 30 2015 20:01
@Qqwy AS i am in my table at the moment, it is too hard to enger code. But you could also add your JS code to the method, i proposed. Tomorrow i will do a closer look if i can extract something from my application.