Eventful.Transition (eventful v3.0.4)

This module providers the macros for building the transition modules

Here is an example:

defmodule MyApp.Post.Transitions do
  use Eventful.Transition, repo: MyApp.Repo

  @behaviour Eventful.Handler

  alias MyApp.Post

  Post
  |> transition([from: "created", to: "published", via: "publish", fn changes ->
    transit(changes)
  end)

  Post
  |> transition([from: "created", to: "deleted", via: "delete", fn changes ->
    transit(changes)
  end)
end

You can also define multiple state machines for example for a given post you can also have a machine for your :visibility field

defmodule MyApp.Post.Visibilities do
  use Eventful.Transition, repo: MyApp.Repo, eventful_state: :visibility

  @behaviour Eventful.Handler

  alias MyApp.Post

  Post
  |> transition([from: "private", to: "public", via: "publicize", fn changes ->
    transit(changes)
  end)

  Post
  |> transition([from: "public", to: "private", via: "privatize", fn changes ->
    transit(changes)
  end)
end

Link to this section Summary

Functions

The transition macro allows you to define the state machine for your transitions

Link to this section Types

@type t() :: %Eventful.Transition{
  event: struct(),
  resource: struct(),
  trigger: map() | nil
}

Link to this section Functions

Link to this macro

transition(module, options, expression)

(macro)

The transition macro allows you to define the state machine for your transitions

Post
|> transition([from: "created", to: "published", via: "publish", fn changes ->
  transit(changes)
end)