Sha256: 601af969b081aa0b6acb01326f5c7774264ee148e1195807dfe12958a9b9ea8e

Contents?: true

Size: 1.36 KB

Versions: 4

Compression:

Stored size: 1.36 KB

Contents

if RUBY_ENGINE == 'opal'
  require 'console'; def console; $console; end
  require_relative 'ovto/actions'
  require_relative 'ovto/app'
  require_relative 'ovto/component'
  require_relative 'ovto/fetch'
  require_relative 'ovto/runtime'
  require_relative 'ovto/state'
  require_relative 'ovto/version'
  require_relative 'ovto/wired_actions'
else
  require 'ovto/version'
  require 'opal'; Opal.append_path(__dir__)
end

module Ovto
  # JS-object-safe inspect
  def self.inspect(obj)
    if `obj.$inspect`
      obj.inspect
    else
      `JSON.stringify(#{obj}) || "undefined"`
    end
  end

  # Call block. If an exception is raised and there is a tag with `id='ovto-debug'`,
  # describe the error in that tag
  def self.log_error(&block)
    return block.call
  rescue Exception => ex
    raise ex if `typeof document === 'undefined'`  # On unit tests

    div = `document.getElementById('ovto-debug')`
    if `div && !ex.OvtoPrinted`
      %x{
        div.textContent = "ERROR: " + #{ex.class.name};
        var ul = document.createElement('ul');
        // Note: ex.backtrace may be an Array or a String
        #{Array(ex.backtrace)}.forEach(function(line){
          var li = document.createElement('li');
          li.textContent = line;
          ul.appendChild(li);
        });
        div.appendChild(ul);
        ex.OvtoPrinted = true;
      }
    end
    raise ex
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ovto-0.2.3 lib/ovto.rb
ovto-0.2.2 lib/ovto.rb
ovto-0.2.1 lib/ovto.rb
ovto-0.2.0 lib/ovto.rb