Skip to content
This repository was archived by the owner on Oct 19, 2018. It is now read-only.
This repository was archived by the owner on Oct 19, 2018. It is now read-only.

README.md example does not work #210

@kWhittington

Description

@kWhittington

Hi,

Trying to switch from JSPM to OpalRB and hyper-react. I've tried following the README.md but it results in a runtime error (in the browser console): every: undefined method every' for main`

I've also tried to follow the two links in the README.md given for gem installation rather than using reactrb-express (http://ruby-hyperloop.io/get_started/, http://ruby-hyperloop.io/installation/) but the first is specifically for reactrb-express and the second is for integration with Rails.

I'm developing a static site and followed OpalRB's instructions here but I'm now stuck trying to figure out which gems need to be installed and what api the classes or modules are providing. It's especially confusing since there aren't any examples with require statements in them.

From reading various reference pages (some older), I believe I need the following:

Gemfile

source 'https://rubygems.org'

gem 'hyper-react'
gem 'opal'
gem 'opal-browser'
gem 'opal-jquery'
gem 'opal-rspec'
gem 'rake'
gem 'rubocop'

Rakefile

require 'bundler'
Bundler.require

Opal.append_path(File.expand_path('../app', __FILE__))

require 'opal'
require 'opal/rspec/rake_task'

desc 'Compile app/application.rb to build.js'
task :build do
  File.binwrite('build.js', Opal::Builder.build('application').to_s)
end

Opal::RSpec::RakeTask.new do |_, task|
  task.runner = :node
end

app/application.rb

require 'opal'
require 'browser'
require 'opal-jquery'
require 'react/react-source'
require 'hyper-react'

class HelloWorld < React::Component::Base
  param :time, type: Time
  render do
    p do
      span { "Hello, " }
      input(type: :text, placeholder: "Your Name Here")
      span { "! It is #{params.time}"}
    end
  end
end

every(1) do
  Element["#example"].render do
    HelloWorld(time: Time.now)
  end
end

I first looked at reactrb-express and it was nice to not have to compile, but I didn't see how I could load other libraries via a Gemfile or make tests for the components via opal-rspec.

If anyone could point me in the right direction where there's solid instructional material to stand up a server-less application with hyper-react, I'd really appreciate it.

Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions