Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Allow Collection to receive falsy `comparator` to override default #1342
The alternative to this is something like
new Collection models, comparator: ->
but that seems a little dirty to me as I don't want to sort it differently or with a 'fake' sort function, but rather not sort it all like a vanilla Backbone.Collection would do. This allows me to pass in
new Collection models, comparator: false # or null or '' or 0
to return the collection to 'no sort' mode. I came across this while implementing a search. Every other time I want this collection to sort by a name.
class Collection extends Backbone.Collection comparator: (model) -> model.get 'name'
But, the order of items initialized in the collection from the search is specific to the query function. When I do
new Collection searchResults, comparator: false
I can keep my order.
I was thinking I'd add the to above "Passing false as the comparator option will prevent sorting."
How's that sound?