-
Notifications
You must be signed in to change notification settings - Fork 1
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
Conversation
jspolancor
commented
Feb 28, 2022
- 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
Creates the cleanFalsyBooleans to mutate html props
There was a problem hiding this 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 beupdate
) - 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]) => { |
There was a problem hiding this comment.
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`
There was a problem hiding this comment.
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> { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
The Readme was updated, I'll create the PR to the muban repo in a moment |