Pass metadata to changesets via keyword list #94
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In the past we have had requests from applications where we needed additional metadata in the changeset function. For example, the
assigns
or the name of the formtarget
. We solved this by supporting multiple changeset functions with different arity.We were not happy with this solution as additional metadata would further increase the arity.
For this reason we now change the arity of all changeset functions called by Backpex to
3
. The first and second parameters contain the item and the params as you know them from Ecto changesets.The third parameter is a keyword list containing any additional metadata passed to the changeset.
At the moment we pass the following metadata to changesets
:assigns
- the assigns:target
- the name of theform
target that triggered the changeset callThe keyword list allows us to easily add additional metadata without having to support another changeset function with a different arity.
As part of these changes, the changeset functions of the Item Actions and Resource Actions are also being adapted to conform to the LiveResource.
The following breaking changes will be introduced:
changeset/3
function to be passed to theBackpex.LiveResource
.changeset/3
instead ofchangeset/2
inBackpex.ResourceAction
.changeset/3
instead ofchangeset/2
inBackpex.ItemAction
.If you do not need any metadata in your changeset, you can of course mark the param as unused with an underscore and simply dont use it.