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

make mask() recursive, allow type() pass unknown properties through in mask=true mode #629

Merged
merged 2 commits into from
Jan 27, 2021

Conversation

dko-slapdash
Copy link
Contributor

@dko-slapdash dko-slapdash commented Jan 26, 2021

…n mask=true mode

- Make mask() and Struct.mask() running masking recursively, fixes ianstormtaylor#618
- Let type() still keep unknown props when mask() mode is used, fixes ianstormtaylor#619
- Add unit tests
- Adds a couple more sentence to the docs
- Do not remove masked() coercion for backward compatibility reasons (it may still be useful)
@dko-slapdash
Copy link
Contributor Author

Hope this PR's code quality passes the library's standards bar; if not - please advice what to improve, I'm happy to do it.

Copy link
Owner

@ianstormtaylor ianstormtaylor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thank you for the clean PR @dko-slapdash. Just one comment inline about a tweak I think we need to make.

const ctx: Context = { path, branch }

if (coerce) {
if (
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the masking should happen after the coercing below, because the coercing is what guarantees we've cloned the input. Otherwise as written this will be mutating the input unexpectedly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, will do. In the original masked() implementation, masked's coercion was running first though, and then the struct's own coercion:

@dko-slapdash
Copy link
Contributor Author

dko-slapdash commented Jan 27, 2021

I just pushed the commit which flips the order of masking and coercion as you requested. Hope you're fine with the difference in behavior in comparison to the upstream where masking was running vice versa, i.e. before the own coercion.

I actually think that masking-after-coercion (which you proposed) is better, because it gives the custom coercion functions more freedom (e.g. they can do some backward compatibility work with the previous props before those props are wiped).

@ianstormtaylor
Copy link
Owner

@dko-slapdash interesting, yeah I think coercing before masking makes the most sense.

I think I want to get rid of masked anyways, since 90% of the use case I think is in using mask to omit things on-demand instead of always masking. So no worries about the slight change in behavior because I'll likely do a breaking change for that already.

@ianstormtaylor ianstormtaylor added improvement ✶ breaking Changes that would mean a breaking API change labels Jan 27, 2021
@ianstormtaylor ianstormtaylor merged commit 01b8ee0 into ianstormtaylor:main Jan 27, 2021
@dko-slapdash
Copy link
Contributor Author

Thanks Ian! This PR would finalize our migration process from yup.

@ianstormtaylor
Copy link
Owner

@dko-slapdash that's great to hear!

maxadv pushed a commit to maxadv/superstruct that referenced this pull request Feb 8, 2021
* main: (73 commits)
  Bump @typescript-eslint/eslint-plugin from 4.14.0 to 4.14.1
  Bump @typescript-eslint/parser from 4.14.0 to 4.14.1
  Bump rollup from 2.38.0 to 2.38.3
  Bump eslint from 7.18.0 to 7.19.0
  v0.14.0
  update changelog
  remove masked coercion, in favor of mask
  make mask() recursive, allow type() pass unknown properties through in mask=true mode (ianstormtaylor#629)
  Bump eslint-config-prettier from 6.15.0 to 7.2.0 (ianstormtaylor#625)
  Bump @typescript-eslint/parser from 4.13.0 to 4.14.0
  Bump @typescript-eslint/eslint-plugin from 4.13.0 to 4.14.0
  Bump rollup from 2.36.2 to 2.38.0
  Bump @types/lodash from 4.14.167 to 4.14.168
  Bump @types/node from 14.14.21 to 14.14.22
  Bump @typescript-eslint/parser from 4.12.0 to 4.13.0
  Bump @typescript-eslint/eslint-plugin from 4.12.0 to 4.13.0
  Bump @types/node from 14.14.20 to 14.14.21
  Bump rollup from 2.36.1 to 2.36.2
  Bump eslint from 7.17.0 to 7.18.0
  v0.13.3
  ...
@dimaqq dimaqq mentioned this pull request Jun 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✶ breaking Changes that would mean a breaking API change improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

let type() still keep unknown props when mask() is used mask() is not recursive
2 participants