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
suggestfunction is passed to thesourcecallback, if the user is still typing, it seems that thethat.valvalue may have changed beforesuggestis called. This can result in caching completions for the incorrectthat.valvalue.For example, I observed when typing "umbrella" that the results for "umb" could be cached against
that.valof "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
suggestfunction and uses.bindat the time the function is passed tosourceto 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 tosourcewhen we invoked it.I'm not sure from this project's README what your policy is on browser support.
Function.prototype.bindworks 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.