Sha256: e97b4134f49487e9f6b371d8f9ddeb212604ffe40ec24e65b0b28e975bf378b9

Contents?: true

Size: 430 Bytes

Versions: 1

Compression:

Stored size: 430 Bytes

Contents

require 'react'

class Timer < React::Component

  def initial_state
    { seconds_elapsed: 0 }
  end

  def tick
    set_state(seconds_elapsed: state[:seconds_elapsed] + 1)
  end

  def component_did_mount
    @interval = window.setInterval(-> { tick }, 1000)
  end

  def component_will_unmount
    window.clearInterval(@interval)
  end

  def render
    div("Seconds Elapsed: #{state[:seconds_elapsed]}")
  end

end

Timer.run

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
opal-react-0.0.5 examples/timer/application.rb