Sha256: 952a244e15f82cdb759f92bfae823aa836dc44a50fe01920169cf2a7d37070a5

Contents?: true

Size: 987 Bytes

Versions: 22

Compression:

Stored size: 987 Bytes

Contents

class ReactAPIDemo

  include React::Component

  before_mount do
    @click_count = 0 # normally we would just use a state variable, but we want to demo using force_update!
  end

  after_mount do
    # to demonstrate the use of dom_node we will attach a click handler AFTER rendering is complete
    Element[dom_node].on(:click) do
      alert("I got attached using some low level stuff... now watch and you will see I will force a rerender") if @click_count == 0
      @click_count += 1
      force_update!
    end
  end

  def render
    #  Normally you would just attach the handler directly to the node like this:
    # "Click Me Please".on(:click) { alert 'I was attached during rendering' }
    if mounted?
      "I was already mounted, and you have clicked me #{@click_count} time#{'s' if @click_count > 1}, but you can click me again!" #.on(:click) { alert("I was attached the normal way")}
    else
      "This is the first render.  click me to rerender!"
    end

  end

end

Version data entries

22 entries across 22 versions & 2 rubygems

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