Skip to content

Instantly share code, notes, and snippets.

@Kelin2025
Created March 17, 2018 19:24
Show Gist options
  • Save Kelin2025/b047c27d0ccb9d76abf5100e0618e6f0 to your computer and use it in GitHub Desktop.
Save Kelin2025/b047c27d0ccb9d76abf5100e0618e6f0 to your computer and use it in GitHub Desktop.
Apicase debounce
const search = doRequest({
url: '/search',
options: { immediate: false, debounce: 2000 }
})
/* Spamming requests while typing */
search.start({ query: { text: 'H' } })
search.start({ query: { text: 'He' } })
search.start({ query: { text: 'Hel' } })
search.start({ query: { text: 'Hell' } })
search.start({ query: { text: 'Hello' } })
search.start({ query: { text: 'Hello ' } })
search.start({ query: { text: 'Hello w' } })
search.start({ query: { text: 'Hello wo' } })
search.start({ query: { text: 'Hello wor' } })
search.start({ query: { text: 'Hello worl' } })
search.start({ query: { text: 'Hello world' } })
search.start({ query: { text: 'Hello world!' } })
/* Listen when it really starts */
search.on('start', console.log)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment