This repository has been archived by the owner. It is now read-only.
fix(clients): Always sort the current device first. #4430
Merged
Conversation
| @@ -59,6 +59,9 @@ define(function (require, exports, module) { | |||
| if (a.get('isCurrentDevice')) { | |||
| return -1; | |||
| } | |||
| if (b.get('isCurrentDevice')) { | |||
vladikoff
Nov 21, 2016
Contributor
👍 yessss!
|
Thanks for the PR, randomized is fine here, if it is wrong we can easily find the issue. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
The client sorting logic was only putting the current device first if it happened to appear on the left-hand-side of a comparison. This fixes it to detect the current device on either side. It also fixes what looked like a typo in a later comparison (comparing
aandbobjects rather thanaNameandbNamestrings).The tests were passing because the order of the input array happened to cause the current device to compare correctly, and I was in two minds about how to fix that issue. We could write a separate test for "puts the current device first when it's in a variety of different positions in the input list" but that felt like a lot of repetition. Randomizing the order of the input list seemed better on balance, because it would not depend on implementation details of the underlying sort, and because it would also capture other edge-cases that we haven't noticed.
But I'm aware that randomizing tests is not everyone's cup of tea, so let me know if you don't like it, and I'll replace it with a separate deterministic test case.
@vladikoff r?