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

ValidationChangeset with external validation compatibility #168

Merged
merged 17 commits into from
Apr 13, 2022

Conversation

snewcomer
Copy link
Collaborator

@snewcomer snewcomer commented Mar 21, 2022

This PR adds a separate Changeset with yup compatibility. Will be used to flush out new ideas.

Limited API compared to the original Changeset.

Yup Changeset - https://github.com/jquense/yup

  • ✂️ save
  • errors are required to be added to the Changeset in manually after validate
  • ✂️ cast
  • ✂️ merge
  • validate takes a callback with the sum of changes. In user land you will call changeset.validate((changes) => yupSchema.validate(changes))

ref #146

ref #144

    let userSchema = object({
      age: number().required().min(21)
    });
    let dummyChangeset = Changeset(dummyModel, userSchema);
    dummyChangeset.set('age', 2);
    try {
      await dummyChangeset.validate();
      dummyChangeset.removeErrors();
    } catch (e) {
      // without `abortEarly: false`.  Still determining what API to use from yup
      dummyChangeset.addError(e.path, { value: e.value.age, validation: e.message });
    }

@snewcomer snewcomer added the enhancement New feature or request label Mar 21, 2022
@snewcomer snewcomer self-assigned this Mar 21, 2022
@snewcomer snewcomer added the WIP label Mar 29, 2022
@snewcomer snewcomer marked this pull request as ready for review April 8, 2022 15:39
@snewcomer snewcomer merged commit b5e44b5 into main Apr 13, 2022
@snewcomer snewcomer deleted the sn/yup-changeset branch April 13, 2022 12:16
@snewcomer snewcomer changed the title ValidationChangeset with yup compatibility ValidationChangeset with external validation compatibility Apr 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request WIP
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant