-
Notifications
You must be signed in to change notification settings - Fork 6.7k
refactor(accordion): use optional binding for isOpen
#1596
Conversation
I viewed your changes and I don't see anything strange, a good step in simplifying things:thumbsup: |
@Gamemaniak There is a similar pattern in carousel if you care ;-) |
Looks good to me. Again, awesome change. Good to clean up after AngularJS 1.2. Just one thing, the coercion bugs me a little. |
scope.$watch('isOpen', function(value) { | ||
if ( value ) { | ||
scope.isOpen = !!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.
This coercion bugs me a little as it causes the watcher to get triggered twice if isOpen is set to a truthy value that's not true
.
Say isOpen = "abc"
, first digest is set to !!"abc"
which is true
, watcher runs again because the isOpen changed from "abc" to true
.
I'll argue that if (value)
is adequate. Though that means isOpen may not be a boolean if the user decides to set it to something else.
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 you are right, scope.isOpen = !!value
has to be removed. What about this:
scope.$watch('isOpen', function(value) {
if ( !!value ) {
accordionCtrl.closeOthers(scope);
}
});
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.
If I recall, if (value)
is good enough, as JavaScript automatically does the !! coercion so the result is equivalent.
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.
Yeah, you are right, those are equivalent :-)
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'm happy about this refactor and more to come! 👍
@bekos Wil do that tomorrow, I presume you you're referring to the slide directive? |
@Gamemaniak Yes. |
Awesome @bekos 👍 |
No description provided.