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

Use in Ecto Changeset pipeline #2

Open
byjpr opened this issue Aug 24, 2018 · 0 comments
Open

Use in Ecto Changeset pipeline #2

byjpr opened this issue Aug 24, 2018 · 0 comments
Labels
enhancement New feature or request

Comments

@byjpr
Copy link
Owner

byjpr commented Aug 24, 2018

Currently MapRewire returns both the original map and the new map. This means we need to create boilerplate to be able to use MapRewire in a pipeline:

  def changeset(variant, params) do
    variant
    |> normalize_data()
    |> cast(
      params,
      ~w(shopify_id title price weight compare_at_price requires_shipping sku available image_id option1 option2 option3)
    )
  end

  defp normalize_data(data) do
    [_old, new] = data <~> @transforms
    new
  end

To reduce the amount of boilerplate needed to use MapRewire we should consider creating a normalize_data function that can be used in a typical changeset:

  def changeset(variant, params) do
    variant
    |> normalize_data(params, @transforms)
    |> cast(
      params,
      ~w(shopify_id title price weight compare_at_price requires_shipping sku available image_id option1 option2 option3)
    )
  end
@byjpr byjpr added the enhancement New feature or request label Aug 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant