Skip to content

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

Development

Successfully merging this pull request may close these issues.

all-upper-case words should always be considered correct suggest not suggestion capitalized words problematic replacementTable suggest behaviour

3 participants