# `Emerge.Engine.Patch`
[🔗](https://github.com/emerge-elixir/emerge/blob/v0.2.1/lib/emerge/engine/patch.ex#L1)

Diff and encode patch operations for Emerge.Engine.Element trees.

# `nearby_slot`

```elixir
@type nearby_slot() :: :behind | :above | :on_right | :below | :on_left | :in_front
```

# `patch`

```elixir
@type patch() ::
  {:set_attrs, term(), map()}
  | {:set_children, term(), [term()]}
  | {:set_nearby_mounts, term(), [{nearby_slot(), term()}]}
  | {:insert_subtree, term() | nil, non_neg_integer(),
     Emerge.Engine.Element.t()}
  | {:insert_nearby_subtree, term(), non_neg_integer(), nearby_slot(),
     Emerge.Engine.Element.t()}
  | {:remove, term()}
```

# `decode`

```elixir
@spec decode(binary()) :: [patch()]
```

Decode a binary command stream into patches.

# `diff`

```elixir
@spec diff(Emerge.Engine.Element.t(), Emerge.Engine.Element.t()) :: [patch()]
```

Compute patches between two trees (expects numeric ids).

# `encode`

```elixir
@spec encode([patch()]) :: binary()
```

Encode patches into a binary command stream.

---

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