# `Macaw.Frame.Writes`
[🔗](https://github.com/dcoai/macaw_frame/blob/v0.1.0/lib/macaw/frame/writes.ex#L1)

What a model writes (spec/03 §5): a Frame changes the page only by emitting events, and
the host applies them to the page's state.

- **Standard writes** (§5.1): a model's `writes/1` answers `%{"selection" => :identity}`
  where a pick of a row with a declared identity is possible, and `%{"window" =>
  :window}` where a brush, a zoom or a view writes the window. `union/1` is the Frame's
  declaration over its frames.
- **`:local` keys** (§5.2, `keys/2`): named by the cell's `sync` group, `<group>`,
  `<group>.brush`, `<group>.item` and `<group>.view`, each with its domain type; none
  without a group. They carry domain values, never pixels.
- **Gestures as events** (§5.3): a finished gesture, already in domain units, becomes a
  `Macaw.Data.Event`: `"brush"` and `"zoom"` with `%{from, to}` ascending, `"reset"` with
  `nil`, `"pick"` with the row's declared fields as `[field, value]` pairs and its
  declared identity, `"view"` with `%{box: %{west, south, east, north}}`. The five
  names are reserved (`reserved/0`).

A gesture is a map: `kind` (`:brush`, `:zoom`, `:pan`, `:reset`, `:pick`, `:view`),
`instance` (the context's instance) and `time` (the holder's now), and by kind `from`
and `to` (domain values), `served` (`%{from, to}`, the delivery's served window), `row`
and `schema` (a pick's typed row and its slot's schema), `box` (a view's). This replaces
visualize's `Visualize.Board.Server.brush/2` and `select/2` and the sync bus's payloads.

# `event`

```elixir
@type event() :: Macaw.Data.Event.t()
```

An event the Frame emits.

# `brush`

```elixir
@spec brush(Macaw.Frame.Coordinates.Model.t(), map()) :: {:ok, event()} | :none
```

A finished brush (§5.3): `"brush"` with `%{from, to}` ascending, `nil` identity.

# `domain_type`

```elixir
@spec domain_type(term()) :: :time | :number | nil
```

The domain type a scale's values have on the bus: `:time` or `:number`, `nil` for neither.

# `event`

```elixir
@spec event(Macaw.Frame.Coordinates.Model.t(), map(), String.t(), term(), map() | nil) ::
  {:ok, event()} | :none
```

An event of the model's frame, `{:ok, event}`, or `:none` when it cannot be built.

# `follow`

```elixir
@spec follow(Macaw.Frame.Coordinates.Model.t(), term(), keyword()) ::
  Macaw.Draw.IR.Element.t() | Macaw.Frame.Coordinates.Model.t() | nil
```

What a frame draws following a key of its group (§5.2): `{:value, v}` the crosshair at
`x(v)` across the plot; `{:brush, %{from, to}}` the band between them; `{:item,
identity}` an outline of every keyed element of `scene` whose row has the identity
(`identities` maps `{layer, row}` to a row's identity); `{:view, box}` the geographic
model's view moved to the box (its projection fitted to it). `nil` for a value the
model cannot follow.

# `keys`

```elixir
@spec keys(term(), term()) :: %{required(String.t()) =&gt; atom()}
```

The `:local` keys of a sync group (§5.2): each of `keys` (`:value` with its domain type,
`:brush`, `:item`, `:view`) under the group's name; `%{}` with no group.

# `pick`

```elixir
@spec pick(Macaw.Frame.Coordinates.Model.t(), map()) :: {:ok, event()} | :none
```

A pick (§5.3): the row's declared fields as `[field, value]` pairs in declared order and
its declared identity as a map of field to value; a pick of nothing (no row) is `[]` and
`nil`. A row with no declared identity carries `nil` and its list.

# `reserved`

```elixir
@spec reserved() :: [String.t(), ...]
```

The runtime's reserved event names (§5.3): a layer's declared event may not use them.

    iex> Macaw.Frame.Writes.reserved()
    ["brush", "zoom", "reset", "pick", "view"]

# `reserved?`

```elixir
@spec reserved?(term()) :: boolean()
```

Whether a name is reserved, read by spelling.

# `reset`

```elixir
@spec reset(Macaw.Frame.Coordinates.Model.t(), map()) :: {:ok, event()} | :none
```

A reset (§5.3): `"reset"` with `nil` value and identity, which clears `window`.

# `selection`

```elixir
@spec selection(Macaw.Frame.Coordinates.Model.t()) :: %{
  optional(String.t()) =&gt; :identity
}
```

The `selection` write a model declares (§5.1): `%{"selection" => :identity}` when the
design's interaction picks on this frame and a layer reads a slot with a declared
identity, else `%{}`.

# `union`

```elixir
@spec union(term()) :: %{required(String.t()) =&gt; :identity | :window}
```

The Frame's `writes` declaration (§5.1): the union of its realized frames' `writes/1`.

# `view`

```elixir
@spec view(Macaw.Frame.Coordinates.Model.t(), map(), map()) :: {:ok, event()} | :none
```

A geographic view (§5.3): `"view"` with `%{box: %{west, south, east, north}}`.

# `zoom`

```elixir
@spec zoom(Macaw.Frame.Coordinates.Model.t(), map()) :: {:ok, event()} | :none
```

A finished zoom or pan of `x` (§5.3, §6.4): `"zoom"` with the extent when it needs more
detail (it reaches outside the `served` window or spans less than half of it), else
`:none`: the client's transform of what is drawn.

---

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