If source
callback is slow, suggest
may get the wrong that.val
to cache
#64
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When the
suggest
function is passed to thesource
callback, if the user is still typing, it seems that thethat.val
value may have changed beforesuggest
is called. This can result in caching completions for the incorrectthat.val
value.For example, I observed when typing "umbrella" that the results for "umb" could be cached against
that.val
of "umbr" and then incorrect results would be displayed if I deleted letters from the end of the full word.This PR adds the value for which we are looking for suggestions as a parameter to the
suggest
function and uses.bind
at the time the function is passed tosource
to record the value at the time of invocation. This way, when we cache values fromsource
, we cache them against the same value that was passed tosource
when we invoked it.I'm not sure from this project's README what your policy is on browser support.
Function.prototype.bind
works on all modern browsers, but breaks on IE8 and earlier, for example. Will that prevent you from accepting this PR? If so, I can work around it.