Module: Plushie::App
- Defined in:
- lib/plushie/app.rb,
sig/plushie/app.rbs
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}")
("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
Instance Method Summary collapse
- #handle_renderer_exit ⇒ Object
-
#init ⇒ Object
Required callbacks.
- #settings ⇒ Hash[Symbol, untyped]
-
#subscribe ⇒ Array[Subscription::Sub]
Optional callbacks with defaults.
- #update ⇒ untyped, [untyped, Command::Cmd]
- #view ⇒ Node, Array[Node]
- #window_config ⇒ Hash[Symbol, untyped]
Instance Method Details
#handle_renderer_exit ⇒ Object
14 |
# File 'sig/plushie/app.rbs', line 14
def handle_renderer_exit: (untyped model, untyped reason) -> untyped
|
#init ⇒ Object
Required callbacks
6 |
# File 'sig/plushie/app.rbs', line 6
def init: (Hash[Symbol, untyped] opts) -> untyped
|
#settings ⇒ Hash[Symbol, untyped]
12 |
# File 'sig/plushie/app.rbs', line 12
def settings: () -> Hash[Symbol, untyped]
|
#subscribe ⇒ Array[Subscription::Sub]
Optional callbacks with defaults
11 |
# File 'sig/plushie/app.rbs', line 11
def subscribe: (untyped model) -> Array[Subscription::Sub]
|
#update ⇒ untyped, [untyped, Command::Cmd]
7 |
# File 'sig/plushie/app.rbs', line 7
def update: (untyped model, untyped event) -> (untyped | [untyped, Command::Cmd])
|
#view ⇒ Node, Array[Node]
8 |
# File 'sig/plushie/app.rbs', line 8
def view: (untyped model) -> (Node | Array[Node])
|
#window_config ⇒ Hash[Symbol, untyped]
13 |
# File 'sig/plushie/app.rbs', line 13
def window_config: (untyped model) -> Hash[Symbol, untyped]
|