Sha256: 84bbd5d62c0e739327e9b2a3bf68a0ad5eaf0f4c4f4a83f380511ae719aa1ce5

Contents?: true

Size: 1.25 KB

Versions: 36

Compression:

Stored size: 1.25 KB

Contents

class HelloMessage

  include React::Component                    # will create a new component named HelloMessage
  
  MSG = {great: 'Cool!', bad: 'Cheer up!'}

  optional_param :mood
  required_param :name
  define_state   :foo, "Default greeting"

  before_mount do
    foo! "#{name}: #{MSG[mood]}" if mood      # change the state of foo using foo!, read the state using foo
  end

  after_mount :log                            # notice the two forms of callback

  def log
    puts "mounted!"
  end
  
  def render                                  # render method MUST return just one component  
    div do                                    # basic dsl syntax component_name(options) { ...children... }                                    
      span { "#{foo} #{name}!" }              # all html5 components are defined with lower case text
    end
  end
  
end

class Basics
  
  include React::Component

  def render
    HelloMessage name: 'John', mood: :great   # new components are accessed via the class name
  end
  
end

# later we will talk about nicer ways to do this:  For now wait till doc is loaded
# then tell React to create an "App" and render it into the document body.

# `window.onload = #{lambda {React.render(React.create_element(App), `document.body`)}}`

Version data entries

36 entries across 36 versions & 2 rubygems

Version Path
reactrb-0.8.8 example/examples/app/basics.js.rb
reactrb-0.8.7 example/examples/app/basics.js.rb
reactrb-0.8.6 example/examples/app/basics.js.rb
reactrb-0.8.5 example/examples/app/basics.js.rb
reactrb-0.8.4 example/examples/app/basics.js.rb
reactrb-0.8.3 example/examples/app/basics.js.rb
reactrb-0.8.1 example/examples/app/basics.js.rb
reactrb-0.8.0 example/examples/app/basics.js.rb
reactrb-0.7.42 example/examples/app/basics.js.rb
reactive-ruby-0.7.41 example/examples/app/basics.js.rb
reactive-ruby-0.7.40 example/examples/app/basics.js.rb
reactive-ruby-0.7.39 example/examples/app/basics.js.rb
reactive-ruby-0.7.38 example/examples/app/basics.js.rb
reactive-ruby-0.7.36 example/examples/app/basics.js.rb
reactive-ruby-0.7.35 example/examples/app/basics.js.rb
reactive-ruby-0.7.34 example/examples/app/basics.js.rb
reactive-ruby-0.7.33 example/examples/app/basics.js.rb
reactive-ruby-0.7.32 example/examples/app/basics.js.rb
reactive-ruby-0.7.31 example/examples/app/basics.js.rb
reactive-ruby-0.7.30 example/examples/app/basics.js.rb