Skip to content

Commit

Permalink
improvement: test out a pattern where we don't use compile time init …
Browse files Browse the repository at this point in the history
…for changes
  • Loading branch information
zachdaniel committed Mar 1, 2022
1 parent e5a1992 commit d3f5b8a
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 10 deletions.
1 change: 1 addition & 0 deletions lib/ash/changeset/changeset.ex
Expand Up @@ -691,6 +691,7 @@ defmodule Ash.Changeset do

Enum.reduce(changes, changeset, fn
%{change: {module, opts}}, changeset ->
{:ok, opts} = module.init(opts)
module.change(changeset, opts, %{actor: actor})

%{validation: _} = validation, changeset ->
Expand Down
8 changes: 0 additions & 8 deletions lib/ash/resource/change/change.ex
Expand Up @@ -53,14 +53,6 @@ defmodule Ash.Resource.Change do
{:error, "Expected a module and opts, got: #{inspect(other)}"}
end

@doc false
def transform(%{change: {module, opts}} = change) do
case module.init(opts) do
{:ok, opts} -> {:ok, %{change | change: {module, opts}}}
{:error, error} -> {:error, error}
end
end

@doc false
def on(list) do
list
Expand Down
4 changes: 2 additions & 2 deletions lib/ash/resource/dsl.ex
Expand Up @@ -312,8 +312,8 @@ defmodule Ash.Resource.Dsl do
"change relate_actor(:reporter)",
"change {MyCustomChange, :foo}"
],
modules: [:change],
target: Ash.Resource.Change,
transform: {Ash.Resource.Change, :transform, []},
schema: Ash.Resource.Change.action_schema(),
args: [:change]
}
Expand Down Expand Up @@ -375,8 +375,8 @@ defmodule Ash.Resource.Dsl do
"change relate_actor(:reporter)",
"change {MyCustomChange, :foo}"
],
modules: [:change],
target: Ash.Resource.Change,
transform: {Ash.Resource.Change, :transform, []},
schema: Ash.Resource.Change.schema(),
args: [:change]
}
Expand Down

0 comments on commit d3f5b8a

Please sign in to comment.