Skip to content

Purpose of @callback transition_changeset is not clear #12

@vovayartsev

Description

@vovayartsev

Hey 👋

Thanks for a nice & clean library.
One question (pardon if a silly one) is about this callback definitions:

defmodule Fsmx.Fsm do
  ...
  if Code.ensure_loaded?(Ecto) do
    @callback transition_changeset(struct, Fsmx.state_t, Fsmx.state_t) :: Ecto.Changeset.t()
    @callback after_transition_multi(struct, Fsmx.state_t, Fsmx.state_t) ::
                {:ok, struct} | {:error, any}
  end
  ...

I thought the idea was to use @impl when overriding transition_changeset, like here:

defmodule App.StateMachineSchema do
  # ...

  @impl Fsmx.Fsm
  def transition_changeset(changeset, "one", "two", params) do
    # changeset already includes a :state field change
    changeset
    |> cast(params, [:data])
    |> validate_required([:data])
  end

but transition_changeset above accepts 4 params, while callback defines only 3 params.
Also there's no @behaviour in defmacro __using__.

This is not a bug report - just curious what was the original intent around @callback 🙏

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions