Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass metadata to changesets via keyword list #94

Merged
merged 7 commits into from
Feb 12, 2024

Conversation

Flo0807
Copy link
Collaborator

@Flo0807 Flo0807 commented Feb 7, 2024

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 form target. 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 the form target that triggered the changeset call

The 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:

  • Require the changeset/3 function to be passed to the Backpex.LiveResource.
  • Require changeset/3 instead of changeset/2 in Backpex.ResourceAction.
  • Require changeset/3 instead of changeset/2 in Backpex.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.

@Flo0807 Flo0807 changed the title Require changeset/3 instead of changeset/2 Require changeset/3 instead of variable changeset functions Feb 7, 2024
@Flo0807 Flo0807 marked this pull request as draft February 7, 2024 10:14
@Flo0807 Flo0807 changed the title Require changeset/3 instead of variable changeset functions Pass metadata to changesets via keyword list Feb 7, 2024
@Flo0807 Flo0807 marked this pull request as ready for review February 7, 2024 12:43
@Flo0807 Flo0807 added the enhancement Changes that are not breaking label Feb 7, 2024
demo/lib/demo_web/resource_actions/email.ex Outdated Show resolved Hide resolved
mix.exs Show resolved Hide resolved
@Flo0807 Flo0807 merged commit 52afd09 into develop Feb 12, 2024
1 check passed
@Flo0807 Flo0807 deleted the feature/changeset-metadata-keyword-list branch February 12, 2024 07:15
@Flo0807 Flo0807 added breaking-change A breaking change and removed enhancement Changes that are not breaking labels Feb 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change A breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants