# `Plushie.Effect.Result`
[🔗](https://github.com/plushie-ui/plushie-elixir/blob/v0.7.2/lib/plushie/effect/result.ex#L1)

Typed results for platform effect responses.

Every `Plushie.Event.EffectEvent` carries a `result` field whose
shape is one of the structs defined here. Apps pattern-match on
the struct module for richly typed access to the effect outcome,
rather than digging into a generic map.

## Variants

Success:

  * `%FileOpened{path: path}` - `file_open`
  * `%FilesOpened{paths: paths}` - `file_open_multiple`
  * `%FileSaved{path: path}` - `file_save`
  * `%DirectorySelected{path: path}` - `directory_select`
  * `%DirectoriesSelected{paths: paths}` - `directory_select_multiple`
  * `%ClipboardText{text: text}` - `clipboard_read` / `clipboard_read_primary`
  * `%ClipboardHtml{html: html, alt_text: alt_text}` - `clipboard_read_html`
  * `%ClipboardWritten{}` - any clipboard write
  * `%ClipboardCleared{}` - `clipboard_clear`
  * `%NotificationShown{}` - `notification`

Non-success:

  * `%Cancelled{}` - the user dismissed the dialog
  * `%Timeout{}` - no response within the kind's timeout
  * `%Error{message: message}` - platform error
  * `%Unsupported{}` - this backend doesn't support the effect
  * `%RendererRestarted{}` - the renderer was restarted while the
    effect was pending

## Pattern matching

    def update(model, %Plushie.Event.EffectEvent{
      tag: :import,
      result: %Plushie.Effect.Result.FileOpened{path: path}
    }) do
      load_file(model, path)
    end

    def update(model, %Plushie.Event.EffectEvent{
      tag: :import,
      result: %Plushie.Effect.Result.Cancelled{}
    }) do
      model
    end

The legacy tuple shape `{:ok, value}` / `:cancelled` / `{:error, reason}`
is no longer emitted. Pre-1.0, there is no back-compat layer.

# `t`

```elixir
@type t() ::
  Plushie.Effect.Result.FileOpened.t()
  | Plushie.Effect.Result.FilesOpened.t()
  | Plushie.Effect.Result.FileSaved.t()
  | Plushie.Effect.Result.DirectorySelected.t()
  | Plushie.Effect.Result.DirectoriesSelected.t()
  | Plushie.Effect.Result.ClipboardText.t()
  | Plushie.Effect.Result.ClipboardHtml.t()
  | Plushie.Effect.Result.ClipboardWritten.t()
  | Plushie.Effect.Result.ClipboardCleared.t()
  | Plushie.Effect.Result.NotificationShown.t()
  | Plushie.Effect.Result.Cancelled.t()
  | Plushie.Effect.Result.Timeout.t()
  | Plushie.Effect.Result.Error.t()
  | Plushie.Effect.Result.Unsupported.t()
  | Plushie.Effect.Result.RendererRestarted.t()
```

Union of every typed effect result.

# `decode`

```elixir
@spec decode(kind :: String.t(), status :: String.t(), payload :: term()) :: t()
```

Decode a renderer-supplied `(kind, status, result_or_reason)` triple
into the appropriate struct.

`kind` is the effect kind string (e.g. `"file_open"`) used at send
time. `status` is the wire status. For `"ok"`, `payload` is the
decoded result map. For `"error"`, `payload` is the reason string.
Otherwise `payload` is ignored.

# `renderer_restarted`

```elixir
@spec renderer_restarted() :: Plushie.Effect.Result.RendererRestarted.t()
```

Constructor used by the runtime when the renderer restarts with
effects in flight.

# `timeout`

```elixir
@spec timeout() :: Plushie.Effect.Result.Timeout.t()
```

Constructor used by the runtime for the timeout path.

---

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