From c83a74cc50e3153e8663690e787ee98b38da3dca Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Tue, 9 Mar 2021 12:04:12 +0100 Subject: [PATCH] Cleanup compareBuffers --- components/app.js | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/components/app.js b/components/app.js index 6f07e8b..c2708f8 100644 --- a/components/app.js +++ b/components/app.js @@ -67,28 +67,22 @@ function debounce(f, delay) { }; } +function isServerBuffer(buf) { + return buf.type == BufferType.SERVER; +} + +/* Returns 1 if a should appear after b, -1 if a should appear before b, or + * 0 otherwise. */ function compareBuffers(a, b) { - if (a.network < b.network) { - return -1; + if (a.network != b.network) { + return a.network > b.network ? 1 : -1; } - if (a.network > b.network) { - return 1; + if (isServerBuffer(a) != isServerBuffer(b)) { + return isServerBuffer(b) ? 1 : -1; } - - if (a.type == BufferType.SERVER) { - return -1; + if (a.name != b.name) { + return a.name > b.name ? 1 : -1; } - if (b.type == BufferType.SERVER) { - return 1; - } - - if (a.name < b.name) { - return -1; - } - if (a.name > b.name) { - return 1; - } - return 0; }