Add timer to reduce fetch.
This commit is contained in:
		
							parent
							
								
									fa75292e22
								
							
						
					
					
						commit
						22b8b212e5
					
				| 
						 | 
				
			
			@ -1,6 +1,10 @@
 | 
			
		|||
var typingTimer;
 | 
			
		||||
var doneTypingInterval = 500;
 | 
			
		||||
 | 
			
		||||
var app = new Vue({
 | 
			
		||||
    el: '#app',
 | 
			
		||||
    data: {
 | 
			
		||||
        prevTerms: '',
 | 
			
		||||
        searchTerms: '',
 | 
			
		||||
        hits: [],
 | 
			
		||||
        new_depicts: [],
 | 
			
		||||
| 
						 | 
				
			
			@ -14,8 +18,12 @@ var app = new Vue({
 | 
			
		|||
            this.hits = [];
 | 
			
		||||
            this.searchTerms = '';
 | 
			
		||||
        },
 | 
			
		||||
    search(event) {
 | 
			
		||||
        run_search() {
 | 
			
		||||
            var terms = this.searchTerms;
 | 
			
		||||
            if (terms == this.prevTerms) {
 | 
			
		||||
                return;  // no change
 | 
			
		||||
            }
 | 
			
		||||
            this.prevTerms = terms;
 | 
			
		||||
            if (terms.length < 3) {
 | 
			
		||||
                this.hits = [];
 | 
			
		||||
                return;
 | 
			
		||||
| 
						 | 
				
			
			@ -28,6 +36,10 @@ var app = new Vue({
 | 
			
		|||
                .then((data) => {
 | 
			
		||||
                    vm.hits = data.hits;
 | 
			
		||||
                })
 | 
			
		||||
        },
 | 
			
		||||
        search(event) {
 | 
			
		||||
            clearTimeout(typingTimer);
 | 
			
		||||
            typingTimer = setTimeout(this.run_search, doneTypingInterval);
 | 
			
		||||
        }
 | 
			
		||||
    },
 | 
			
		||||
});
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue