twitter/typeahead.js — pull request #979 by geoffp (2014-08-28 20:49:29+00:00)
Title: Pass context and query info to sorter callback functions

This change addresses a need I had to write a sorter function that prioritizes result datums that have certain attributes that are closer to the query string than others. All I needed was access to more information from inside the sorter function, so this change is pretty non-invasive, and should give developers lots of added flexibility to sort results based on the query.

I've passed around some "this" context and added a closure so that "this" in the sorter will refer to the Bloodhound instance, and more importantly, allow sorter function authors to accept a third parameter, which provides the string and tokenized forms of the query. The signature of the function passed to Array.prototype.sort() is preserved exactly as (a, b).

The queryInfo object is created in the get() method so the query tokenizer can be run once per query and not every time the callback executes.

This should solve https://github.com/twitter/typeahead.js/issues/817.