These are chat archives for opal/opal

11th
Jan 2018
G. Gibson
@mistergibson
Jan 11 2018 21:29
Hello everyone
Elia Schito
@elia
Jan 11 2018 22:31
@fkchang interesting stuff, you're never really up-to-date with the JS ecosystem :laughing:

On a similar note this is incredibly similar to the internal framework we grew at work https://github.com/stimulusjs/stimulus

here's a code example:

module Spinner
  extend PersistentEvents
  self.selector = '#spinner, #spinnerFigure'

  on_event 'spinner:updated' do
    spinner_data = $app.state[:spinner]
    if spinner_data && spinner_data.values.any?
      @show = true
    else
      @show = false
    end
    render!
  end

  def self.render
    @show ? element.show : element.hide
  end
end

somewhere else in the app someone calls:

      $app.action! :spinner_start, :filters_update

and when it's done:

      $app.action! :spinner_start, :filters_update
Elia Schito
@elia
Jan 11 2018 22:36
all actions are defined in a single big module, and every action updates the global status (redux inspired):
module Actions
  extend self

  # …

  def spinner_start(state, spinner_key)
    spinner_state = state[:spinner]
    unless spinner_state[spinner_key]
      spinner_state[spinner_key] = true
      $app.trigger 'spinner:updated'
    end
  end

  def spinner_stop(state, spinner_key)
    spinner_state = state[:spinner]
    if spinner_state[spinner_key]
      spinner_state.delete(spinner_key)
      $app.trigger 'spinner:updated'
    end
  end
end
G. Gibson
@mistergibson
Jan 11 2018 23:01
Question: is there an in-line page load option for the jQuery compat layer VS. the application-compile approach?
I need this: http://opalrb.com/docs/guides/v0.11.0/jquery.html -- but want to load my own custom libs over the top of a jQuery-friendly Opal layer.