Quantcast
Channel: Active questions tagged svelte - Stack Overflow
Viewing all articles
Browse latest Browse all 1541

How to debounce / throttle with Svelte?

$
0
0

So i currently have:

App.html

<div><input on:input="debounce(handleInput, 300)"></div><script>  import { debounce } from 'lodash'  export default {    data () {      name: ''    },    methods: {      debounce,      async handleInput (event) {        this.set({ name: await apiCall(event.target.value).response.name })      }    }  }</script>

And get the error Uncaught TypeError: Expected a function at App.debounce. This comes from Lodash so it doesn't seem like the method from Svelte is being passed through.

Extra extra edit

Extra context for how i'm currently achieving it:

oncreate () {  const debounceFnc = this.handleInput.bind(this)  this.refs.search.addEventListener('input', debounce(debounceFnc, 300))}

Viewing all articles
Browse latest Browse all 1541

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>