# `Harlock.App`
[🔗](https://github.com/thatsme/harlock/blob/v0.2.0/lib/harlock/app.ex#L1)

Behaviour for Harlock applications.

An app defines three callbacks:

  * `init/1` — returns the initial model from an arbitrary init argument.
  * `update/2` — given an event and the current model, returns the next
    model, optionally paired with a `Cmd`. Return `:quit` to exit the app.
  * `view/1` — given the current model, returns an element tree.

The simplest app:

    defmodule Counter do
      use Harlock.App

      def init(_), do: %{n: 0}

      def update({:key, {:char, ?+}, []}, m), do: %{m | n: m.n + 1}
      def update({:key, {:char, ?q}, []}, _), do: :quit
      def update(_event, m), do: m

      def view(m) do
        vbox(constraints: [length: 1, fill: 1], children: [
          text("Count: #{m.n}"),
          text("(+ to inc, q to quit)")
        ])
      end
    end

# `model`

```elixir
@type model() :: any()
```

# `msg`

```elixir
@type msg() :: any()
```

# `init`

```elixir
@callback init(any()) :: model() | {model(), Harlock.Cmd.t()}
```

# `subs`
*optional* 

```elixir
@callback subs(model()) :: [Harlock.Sub.t()]
```

# `update`

```elixir
@callback update(msg(), model()) ::
  model() | {model(), Harlock.Cmd.t()} | :quit | {:quit, Harlock.Cmd.t()}
```

# `view`

```elixir
@callback view(model()) :: Harlock.Element.t()
```

---

*Consult [api-reference.md](api-reference.md) for complete listing*
