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

Close issue #597. Fixes the Utils.isEmpty -function #598

Closed
wants to merge 1 commit into from
Closed

Close issue #597. Fixes the Utils.isEmpty -function #598

wants to merge 1 commit into from

Conversation

artiee
Copy link
Contributor

@artiee artiee commented Aug 13, 2013

Close issue #597. Fixes the Utils.isEmpty -function to omit 0 (zero) from falsy values. The if-helper has to only call this function, not do own check for the conditional.

…from falsy values. The if-helper has to only call this function, not do own check for the conditional.
@@ -67,14 +67,15 @@ Handlebars.Utils = {
},

isEmpty: function(value) {
if (!value && value !== 0) {
if(typeof value === 'undefined' || value === null || value === false || value === ""){
Copy link

Choose a reason for hiding this comment

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

typeof value === 'undefined' || value === null can be written more succinctly as value == null (the double-equals will check for both undefined and null). You can save the typeof check since we don't have to worry about ReferenceErrors.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Forgive me for being dense, but how does this change the behavior? Isn't this the exact same logic implemented with || to include cases rather than && to exclude cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For that part yes but the problem is in the base.js. I just tried to write that part in the utils.js more readable because using && as excluding case is harder on the eye. I prefer being explicit. Handlebars still considers 0 as a falsy value. Could you please provide comment on that?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Since it has to go over the wire we prefer smaller code (after minimization) over verbosity. Obviously there is gray room in this as sometimes smaller code is harder to understand but I actually found this implementation harder to understand over "falsy except for zero" as there is more to read.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok. Please refer to pull request #602 which fixes the core problem.

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.

3 participants