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

Updates the h function to allow falsy values on data attributes #4

Merged
merged 7 commits into from
Sep 20, 2022

Conversation

jspolancor
Copy link
Contributor

  • Updates the h function to allow false values on data attributes
  • Creates the cleanFalsyBooleans function to mutate html props
  • Updates tests to reflect the changes

@jspolancor jspolancor linked an issue Feb 28, 2022 that may be closed by this pull request
4 tasks
Copy link
Contributor

@ThaNarie ThaNarie left a comment

Choose a reason for hiding this comment

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

Besides the small comments, I would like to mention:

  • The commit messages are written in the wrong "tense" (updates should be update)
  • I'm missing the updated README (as specified in the task list of the original ticket).
  • It would also be nice to have an accompanied PR on the muban repo to update the docs.

src/lib/mtl.ts Outdated
export function cleanFalsyBooleans(props: Record<string, any>): Record<string, any> {
const stringifiedProps = { ...props };

Object.entries(stringifiedProps).forEach(([key, value]) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think a .entries > .map > .fromEntries is a bit nicer here (instead of the stringifiedProps mutation inside the loop`

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

src/lib/mtl.ts Outdated
/**
* Function to turn falsy boolean prop values to the string 'false'
*/
export function cleanFalsyBooleans(props: Record<string, any>): Record<string, any> {
Copy link
Contributor

Choose a reason for hiding this comment

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

unknown instead of any would probably work here as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

src/lib/mtl.ts Outdated

return vhtml(type, props, children);
// If more prop modifier functions like cleanFalsyBooleans are added we could pipe them here
const mutatedProps = cleanFalsyBooleans(props);
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe naming wise, something like this?

  • processFalsyBooleanProps
  • processedProps

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@jspolancor
Copy link
Contributor Author

Besides the small comments, I would like to mention:

  • The commit messages are written in the wrong "tense" (updates should be update)
  • I'm missing the updated README (as specified in the task list of the original ticket).
  • It would also be nice to have an accompanied PR on the muban repo to update the docs.

The Readme was updated, I'll create the PR to the muban repo in a moment

@ThaNarie ThaNarie merged commit ef0c5a4 into main Sep 20, 2022
@ThaNarie ThaNarie deleted the feature/allow-false-values-on-data-attr branch September 20, 2022 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow false values on data-attributes
2 participants