Module: Plushie::App

Defined in:
lib/plushie/app.rb

Overview

Behaviour module for Plushie apps following the Elm architecture.

Include this module and implement init, update, and view:

class Counter include Plushie::App

Model = Plushie::Model.define(:count)

def init(_opts) = Model.new(count: 0)

def update(model, event)
  case event
  in Event::Widget[type: :click, id: "increment"]
    model.with(count: model.count + 1)
  else
    model
  end
end

def view(model)
  window("main", title: "Counter") do
    column(padding: 16, spacing: 8) do
      text("count", "Count: #{model.count}")
      button("increment", "+")
    end
  end
end

end

view(model) must return a window(...) node or an array of window(...) nodes. Widgets do not live at the top level.

Defined Under Namespace

Modules: Aliases, DefaultCallbacks