# `AshBackendDrivenOptimisticUi.PushId`
[🔗](https://github.com/Undeadlol1/ash_backend_driven_optimistic_ui/blob/v0.1.0/lib/ash_backend_driven_optimistic_ui/push_id.ex#L1)

The id of an optimistic push, computed from the record as it was before the
write: `<type>:<record id>:<updated_at>:<event>:<label>`.

`label` is the `optimistic` action name for a push made inside `optimistic`, and
the answered event's name for a push made inside `on`. The record's
`updated_at` moves on every write, so the next write's ids are new by
themselves and nothing has to be remembered.

The server computes the id with `for/3` both when the client shows the push at once
(through the record's `ctx.push_ids`, see `for_record/1`) and when the
notifier really sends it, so the two match by construction.

An `optimistic` rule of a create or generic action has no record before the
write, so its pushes get no id.

# `declared`

```elixir
@spec declared(Ash.Resource.t()) :: [{atom(), atom()}]
```

The `{event, label}` of every push `resource` declares that has a record before the write.

# `for`

```elixir
@spec for(struct(), atom(), atom()) :: String.t()
```

The id of `event` pushed under `label` by a write to `record`, as `record` is now.

# `for_record`

```elixir
@spec for_record(struct()) :: %{required(atom()) =&gt; %{required(atom()) =&gt; String.t()}}
```

Every declared push id of `record`: `%{event => %{label => id}}`.

# `identified?`

```elixir
@spec identified?(Ash.Resource.t(), atom()) :: boolean()
```

Whether the pushes of `optimistic action` carry an id: its record exists before the write.

# `variable`

```elixir
@spec variable(atom(), atom()) :: String.t()
```

The JSON Logic variable path the compiled push reads its id from.

---

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