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

feat(tabs): makes deselect callback fire before select. fixes #1557. #1566

Closed
wants to merge 1 commit into from

Conversation

jroxendal
Copy link
Contributor

This should fix the call order of the select and deselect callbacks.

angular.forEach(tabs, function(tab) {
tab.active = false;
if(tab.active && tab !== selectedTab) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@jroxendal Is there a way that this function will be called on already active tab? What I mean do we really need the double check?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As the code is written now, this is necessary. On tab click, active is set to true. The active watch is then run, where this function is called and at this time two tabs may actually be active: the 'old' tab (which should be deselected) and the one we just selected. Only one of the deselect callbacks should be run, obviously.

I didn't want to do a complete rewrite, so I left the active watch in the tabs directive in there. In order to avoid the check above, I believe that watch needs to go and some further refractoring to take place.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, you are right about the 2 active tabs, so the double check is needed.

@bekos
Copy link
Contributor

bekos commented Jan 14, 2014

@jroxendal Left some comments on the code. This is on the right track but still needs some work. Also, about the tesst you should create a separate describe section for this, try not to "pollute" the other cases with spies etc.

@pkozlowski-opensource
Copy link
Member

@jroxendal would be awesome if you could address @bekos comments so this one can be landed.

@jroxendal
Copy link
Contributor Author

@pkozlowski-opensource i'm on the case! :)

@jroxendal
Copy link
Contributor Author

@bekos I've made the changes you suggested. Please let me know if any further changes are necessary.

Just an observation: currently, if the first tab has been explicitly marked as active=false, it's still set to active=true and its onselect callback i fired. I'd consider this a bug but didn't supply a fix since fixing this means that the tabs widget could be in a state where no tabs are active. It's pretty easy for a user to avoid that state, of course: just don't set active=false on the first tab. Any thoughts on what the correct behavior should be?

@@ -153,6 +152,56 @@ describe('tabs', function() {
});
});

describe('tab callback order', function() {
var execOrder = [];
Copy link
Contributor

Choose a reason for hiding this comment

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

As I said, you don't have to initialize this here, just leave the declaration.
You have to do it inside the beforeEach, so each test does not mess with previous execution orders.

@bekos
Copy link
Contributor

bekos commented Jan 18, 2014

@jroxendal I like your changes! Also left some comments about some small things into the test code.
After these... prepare for landing :-)

@jroxendal
Copy link
Contributor Author

@bekos thanks for the comments, I'll make the relevant changes in the morning!

@jroxendal
Copy link
Contributor Author

@bekos I've followed your advice, it's a lot neater now :)

@bekos bekos closed this in 7474c47 Jan 19, 2014
@bekos
Copy link
Contributor

bekos commented Jan 19, 2014

@jroxendal Nice one :-) Thx!

@jroxendal
Copy link
Contributor Author

@bekos My pleasure, thank you for the code review!

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.

3 participants