Sha256: a7d1975f16d12b5e6e82d28f786e31681eae7aef29d27e581fdc9a98285ccbe5

Contents?: true

Size: 768 Bytes

Versions: 7

Compression:

Stored size: 768 Bytes

Contents

# app/views/components/app.rb
class App < React::Component::Base

  define_state :loading

  def add_new_word
    state.loading! true
    HTTP.get("http://randomword.setgetgo.com/get.php", dataType: :jsonp) do |response|
      Word.create(text: response.json[:Word]).then { state.loading! false }
    end
  end

  def display_word(word)
    LI do
      SPAN(style: {marginRight: 10}) { word.text }
      BUTTON { "delete!" }.on(:click) { word.destroy }
    end
  end

  render(DIV) do
    SPAN(style: {marginRight: 10}) { "Count of Words: #{Word.sorted.count}" }
    if state.loading
      SPAN { "loading..." }
    else
      BUTTON { "add another" }.on(:click) { add_new_word }
    end
    UL do
      Word.sorted.each { |word| display_word word }
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
hyper-mesh-0.6.0 examples/words/app/views/components/app.rb
hyper-mesh-0.5.4 examples/words/app/views/components/app.rb
hyper-mesh-0.5.3 examples/words/app/views/components/app.rb
hyper-mesh-0.5.2 examples/words/app/views/components/app.rb
hyper-mesh-0.5.1 examples/words/app/views/components/app.rb
hyper-mesh-0.5.0 examples/words/app/views/components/app.rb
hyper-mesh-0.4.0 examples/words/app/views/components/app.rb