Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

fix: (sticky | subheader) - fix little bug on refreshElements() #438

Closed
wants to merge 1 commit into from

Conversation

mmaestri
Copy link

A bug in the refreshElements() function caused malfunction in the subheader component. It applies an order over the self.items array based on the top property calculated in refreshPosition(item).

When sorting, the compare function returns a true/false value (a.top > b.top), but it should return an int value (a.top - b.top). Because of this the self.items array is misordered, self.current, self.prev and self.next are miscalculated and the subheader fails to acknowledge changes in sections.

Changing the compare function solves this issue

A bug in the refreshElements() method caused malfunction in the subheader component. It applies an order over the self.items array based on the top property calculated in refreshPosition(item). 

The compare function returns a true/false value (a.top > b.top), but it should return an int value (a.top - b.top). Because of this the self.items array is misordered, self.current, self.prev and self.next are miscalculated and the subheader fails to acknowledge changes in sections.

Changing the compare function solves this issue
@ajoslin
Copy link
Contributor

ajoslin commented Oct 16, 2014

Interesting, I thought sort would convert true & false to 1 & 0. Maybe it doesn't in certain browsers.

@ajoslin
Copy link
Contributor

ajoslin commented Oct 16, 2014

Could you sign the CLA so I can merge this?

@ajoslin ajoslin closed this in d8e5079 Oct 16, 2014
@ajoslin
Copy link
Contributor

ajoslin commented Oct 16, 2014

Fixed on my own - I read the API docs for Array.prototype.sort, and the way you're doing it isn't explicitly supported there. So I did the usual -1 or 1.

@mmaestri
Copy link
Author

I've already signed the CLA, but travis kept me giving validation errors.

Actually that way is not only supported, but the recommended way to compare integers. If you look at the API docs it says

To compare numbers instead of strings, the compare function can simply subtract b from a. The following function will sort the array ascending:

function compareNumbers(a, b) {
  return a - b;
}

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.

2 participants