Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complex setSort() callback #26

Open
frank-weindel opened this issue Oct 9, 2014 · 3 comments
Open

Complex setSort() callback #26

frank-weindel opened this issue Oct 9, 2014 · 3 comments

Comments

@frank-weindel
Copy link

@jmorrell Great work on this library!

One thing I'd like to do is perform sorts using a compareFunction comparator callback similar to how Array.prototype.sort does it. The callback provides two models as arguments (a and b), and the result of the function is whether A is greater than B, vice-vera, or they're equal. This allows you to do much more complex sorts that are multi-layered and don't have to rely on string comparison.

The following issue calls out this issue as it originally appeared in Backbone. The ability to provide a compareFunction-like sort comparator has since been added.

jashkenas/backbone#488

Would this be difficult to add? I might look into doing it if I get some time soon.

@jmorrell
Copy link
Owner

jmorrell commented Oct 9, 2014

Should be possible, and would be a good feature. The relevant code in backbone is here. Note that it switches by testing the number of arguments that the function accepts using Function#length, which we'd want to copy. The code you'd want to modify is in backbone-sorted-collection here.

I'm afraid I don't really have free cycles to work on this at the moment, but I'm happy to review / merge PRs or walk you through code :) Let me know if you want to be added as a collaborator.

@frank-weindel
Copy link
Author

Sorry I didn't respond earlier. That would be great Jeremy.

@sjmcgrath
Copy link

We just bumped up against this. The relevant similar lines in Backbone.js are https://github.com/jashkenas/backbone/blob/24779ae64a3f325f14d49fe6a8e5aa3e5ac1e421/backbone.js#L1026-L1031.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants