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}")
      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

Instance Method Summary collapse

Instance Method Details

#handle_renderer_exitObject

Parameters:

  • model (Object)
  • reason (Object)

Returns:

  • (Object)


14
# File 'sig/plushie/app.rbs', line 14

def handle_renderer_exit: (untyped model, untyped reason) -> untyped

#initObject

Required callbacks

Parameters:

  • opts (Hash[Symbol, untyped])

Returns:

  • (Object)


6
# File 'sig/plushie/app.rbs', line 6

def init: (Hash[Symbol, untyped] opts) -> untyped

#settingsHash[Symbol, untyped]

Returns:

  • (Hash[Symbol, untyped])


12
# File 'sig/plushie/app.rbs', line 12

def settings: () -> Hash[Symbol, untyped]

#subscribeArray[Subscription::Sub]

Optional callbacks with defaults

Parameters:

  • model (Object)

Returns:



11
# File 'sig/plushie/app.rbs', line 11

def subscribe: (untyped model) -> Array[Subscription::Sub]

#updateuntyped, [untyped, Command::Cmd]

Parameters:

  • model (Object)
  • event (Object)

Returns:



7
# File 'sig/plushie/app.rbs', line 7

def update: (untyped model, untyped event) -> (untyped | [untyped, Command::Cmd])

#viewNode, Array[Node]

Parameters:

  • model (Object)

Returns:



8
# File 'sig/plushie/app.rbs', line 8

def view: (untyped model) -> (Node | Array[Node])

#window_configHash[Symbol, untyped]

Parameters:

  • model (Object)

Returns:

  • (Hash[Symbol, untyped])


13
# File 'sig/plushie/app.rbs', line 13

def window_config: (untyped model) -> Hash[Symbol, untyped]