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

Async suggest #45

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open

Async suggest #45

wants to merge 21 commits into from

Conversation

kofifus
Copy link

@kofifus kofifus commented Aug 23, 2016

This PR adds the option of running suggest asynchronously allowing updating the display with results as they come, and stopping a suggestion search midway. Also provides much faster performance and smaller memory use on both synchronous and asynchronous suggests.

The suggest function can now be called in one of three ways:

suggest(word, limit [=5])

  • runs suggest synchronously, same signature as before

suggest(word, limit [=5], doneFunc, progressFunc) where either doneFunc or progressFunc are defined

  • runs suggest asynchronously
  • returns undefined
  • doneFunc (if given) will be called (with the sorted results array) once the search is done
  • progressFunc (if given) will be called (with the new match) whenever a new match is found in the search
  • if progressFunc returns===false the current search will be aborted
  • will do the equivalent of sleep(0) every 200ms

suggest()

  • abort a current search if running

Other changes:

See a working sample in plunkr

This PR makes suggest operating asynchroniously, providing _much_ faster performance, much smaller memory use,  and allowing to stop a suggestion search midway.

suggest : function (word, limit, doneFunc, progressFunc)
  - returns undefined

 - doneFunc (if given) will be called (with the results array) once the search is done
 - progressFunc (if given) will be called (with the new match and the array of all matches so far) whenever a new match is found in the search
 - if progressFunc returns===false the current search will be aborted
 - calling suggest without parameters will abort a current search if running

See a working sample in https://plnkr.co/edit/0y1wCHXx3k3mZaHFOpHT
@cfinke
Copy link
Owner

cfinke commented Sep 20, 2016

To be honest, at this point, there are so many commits and no clear documentation of each commit that I would feel very uneasy merging in these changes.

@kofifus
Copy link
Author

kofifus commented Sep 20, 2016

yeah complicated but work very well ... (and documented)

I wrote this for CodeMirror, without async there is an unacceptable wait between pressing the right click and getting the results.

see the gist here: https://gist.github.com/kofifus/4b2f79cadc871a29439d919692099406
see demo https://plnkr.co/edit/0y1wCHXx3k3mZaHFOpHT?p=info

anyways ..

@MikhailTymchukDX
Copy link

Personally, I don't inspect every commit when review a PR. I check "Files changed" tab only.
This is very useful improvement, because on long words typo hangs entire page.

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