Sha256: f3502e0dd02c1e070bf774f6a127b72b26a72198ffacd5eca31c2d2108a39ca8
Contents?: true
Size: 828 Bytes
Versions: 1
Compression:
Stored size: 828 Bytes
Contents
require 'react' class TodoList < React::Component def render ul( props[:items].map { |item| li({key: item[:id]}, [ item[:text] ]) } ) end end class TodoApp < React::Component def initial_state { items: [], text: '' } end def onChange(e) set_state({text: e.target.value}) end def handleSubmit(e) e.preventDefault() now = Time.now new_item = [{ text: state[:text], id: now.to_i * 1e6 + now.usec }] set_state( items: state[:items] + new_item, text: '' ) end def render div([ h3('TODO'), TodoList(items: state[:items]), form({onSubmit: method(:handleSubmit)}, [ input(onChange: method(:onChange), value: state[:text]), button("Add ##{state[:items].count+1}") ]) ]) end end TodoApp.run()
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
opal-react-0.0.5 | examples/todoapp/application.rb |