enyo.Collection Sorting
JavaScript
// ____ _ ____ _
// / ___| ___ _ __| |_/ ___| _ _ _ __ _ __ ___ _ __| |_
// \___ \ / _ \| '__| __\___ \| | | | '_ \| '_ \ / _ \| '__| __|
// ___) | (_) | | | |_ ___) | |_| | |_) | |_) | (_) | | | |_
// |____/ \___/|_| \__|____/ \__,_| .__/| .__/ \___/|_| \__|
// |_| |_|
enyo.SortSupport = {
sortBy: "",
sortOrder: "asc",
constructed: enyo.inherit(function(sup) {
return function() {
sup.apply(this, arguments);
// setup the instancing right now
this.sortByChanged();
};
}),
sortByChanged: function() {
// try to be a bit more aggressive about determining if the sortBy is computed to avoid unnecessary instancing.
// if no model has been set, the prop can't be computed
// also, if there isn't a sortBy set, this isn't relevant
if(this.model && this.sortBy) {
var computed = this.model.prototype.computed;
if(~enyo.indexOf(this.sortBy, enyo.keys(computed))) {
this.set("instanceAllRecords", true);
}
}
this.sort();
},
sortOrderChanged: function() {
this.sort();
},
instanceAllRecordsChanged: function() {
if(this.instanceAllRecords) {
for(var i=0;i<this.length;i++) {
this.at(i);
}
}
},
add: enyo.inherit(function(sup) {
return function() {
sup.apply(this, arguments);
this.delaySort();
};
}),
remove: enyo.inherit(function(sup) {
return function() {
sup.apply(this, arguments);
this.delaySort();
};
}),
_recordChanged: enyo.inherit(function(sup) {
return function(rec, e, p) {
...