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

Fixed dataset 'true' & 'false' conversions to boolean values in check() #88

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

michalismichailidis1999

Because the data values inside html elements are strings (for example data-vp-repeat="true"), boolean values won't work inside check() function since both "true" and "false" are both true statements in if (objOptions.invertBottomOffset){}. So I checked what was the value in $obj.dataset[dataKey] and if it was "true" or "false" I converted them to boolean values with the helper method I created.

I also made the demo website take the full screen because its easier to work with.

Copy link
Owner

@dirkgroenen dirkgroenen left a comment

Choose a reason for hiding this comment

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

Thanks for your PR, I left some remarks and please remove the updated package-lock.json.

* Turns strings 'true' or 'false' into booleans
*/
const getBooleanStringRepresentation = (val: string): boolean =>
val !== "true" && val !== "false" ? false : val === "true" ? true : false;
Copy link
Owner

Choose a reason for hiding this comment

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

This one is double and can be shortened into val === "true" ? true : false.

Comment on lines 184 to 189
const val =
typeof $obj.dataset[dataKey] !== undefined ?
(
$obj.dataset[dataKey] === "true" || $obj.dataset[dataKey] === "false" ?
getBooleanStringRepresentation($obj.dataset[dataKey]!) : $obj.dataset[dataKey]
) : undefined;
Copy link
Owner

Choose a reason for hiding this comment

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

For this one some of the checks can be removed, since they're implicitly also being done by your true/false expression:

const val = ["true", "false"].includes($obj.dataset[dataKey])
   ? getBooleanStringRepresentation($obj.dataset[dataKey]!)
   :  $obj.dataset[dataKey];

This will check if the value is true or false and if so pass it on to your coercion function. If not it will just pass along the original value (which could be undefined or any other value)

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.

None yet

2 participants