Mercurial > snowl
changeset 261:a7aada4427b7
simplify setting of sort properties and order
author | Myk Melez <myk@mozilla.org> |
---|---|
date | Mon, 25 Aug 2008 17:52:58 -0700 |
parents | f88055405aee |
children | 3c6bbb2dc4e2 |
files | content/list.js content/river.js content/stream.js modules/collection.js |
diffstat | 4 files changed, 18 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/content/list.js Mon Aug 25 17:33:13 2008 -0700 +++ b/content/list.js Mon Aug 25 17:52:58 2008 -0700 @@ -572,7 +572,9 @@ let order = (direction == "ascending" ? 1 : -1); // Perform the sort. - this._collection.sort([property], order); + this._collection.sortProperty = [property]; + this._collection.sortOrder = order; + this._collection.sort(); } };
--- a/content/river.js Mon Aug 25 17:33:13 2008 -0700 +++ b/content/river.js Mon Aug 25 17:52:58 2008 -0700 @@ -317,8 +317,7 @@ // Presumably here we could do messages.reverse(), which would be faster, // but can we be sure the messages started in the reverse of the new state? - this._collection.sort(this._collection.sortProperty, - this._collection.sortOrder); + this._collection.sort(); this.rebuildView(); this._updateURI(); },
--- a/content/stream.js Mon Aug 25 17:33:13 2008 -0700 +++ b/content/stream.js Mon Aug 25 17:52:58 2008 -0700 @@ -146,8 +146,9 @@ this._document = this._window.document; this._collection = new SnowlCollection(); - this._collection.sortProperty = "received"; + this._collection.sortProperty = ["received"]; this._collection.sortOrder = -1; + this._collection.sort(); this.rebuildView(); },
--- a/modules/collection.js Mon Aug 25 17:33:13 2008 -0700 +++ b/modules/collection.js Mon Aug 25 17:52:58 2008 -0700 @@ -232,7 +232,7 @@ // Retrieval // sortProperty gets set to its default value in the constructor - // since the default is an array which would be a singleton if defined here. + // since the default is an array, which would be a singleton if defined here. sortProperty: null, sortOrder: 1, @@ -265,7 +265,7 @@ statement.reset(); } - this.sort(this.sortProperty, this.sortOrder); + this.sort(); // A bug in SQLite breaks relating a virtual table via a LEFT JOIN, so we // can't pull content with our initial query. Instead we do it here. @@ -342,23 +342,25 @@ return statement; }, - sort: function(aProperties, aOrder) { - this.sortProperty = aProperties; - this.sortOrder = aOrder; + sort: function() { + // Reflect these into local variables that the compare function closure + // can access. + let properties = this.sortProperty; + let order = this.sortOrder; // Fall back on subject. // XXX Should we let callers make this decision? - if (aProperties[aProperties.length - 1] != "subject") - aProperties.push("subject"); + if (properties[properties.length - 1] != "subject") + properties.push("subject"); let compare = function(a, b) { - for each (let property in aProperties) { + for each (let property in properties) { if (prepareObjectForComparison(a[property]) > prepareObjectForComparison(b[property])) - return 1 * aOrder; + return 1 * order; if (prepareObjectForComparison(a[property]) < prepareObjectForComparison(b[property])) - return -1 * aOrder; + return -1 * order; } // Return an inconclusive result.