Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

refactor(accordion): use optional binding for isOpen #1596

Closed
wants to merge 1 commit into from

Conversation

bekos
Copy link
Contributor

@bekos bekos commented Jan 16, 2014

No description provided.

@mvhecke
Copy link
Contributor

mvhecke commented Jan 16, 2014

I viewed your changes and I don't see anything strange, a good step in simplifying things:thumbsup:

@bekos
Copy link
Contributor Author

bekos commented Jan 16, 2014

@Gamemaniak There is a similar pattern in carousel if you care ;-)

@chrisirhc
Copy link
Contributor

Looks good to me. Again, awesome change. Good to clean up after AngularJS 1.2.

Just one thing, the coercion bugs me a little.
But running the watcher twice probably won't cause any problems.

scope.$watch('isOpen', function(value) {
if ( value ) {
scope.isOpen = !!value;
Copy link
Contributor

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.

Copy link
Contributor Author

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);
    }
});

Copy link
Contributor

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.

Copy link
Contributor Author

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 :-)

Copy link
Contributor

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! 👍

@mvhecke
Copy link
Contributor

mvhecke commented Jan 16, 2014

@bekos Wil do that tomorrow, I presume you you're referring to the slide directive?

@bekos
Copy link
Contributor Author

bekos commented Jan 17, 2014

@Gamemaniak Yes.

@bekos bekos closed this in 0702403 Jan 18, 2014
@pkozlowski-opensource
Copy link
Member

Awesome @bekos 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants