Skip to content

Commit 57a01f1

Browse files
committed
fix: #2767 Search field loses focus after search
Signed-off-by: Kostiantyn Miakshyn <molodchick@gmail.com>
1 parent 62a5fe0 commit 57a01f1

2 files changed

Lines changed: 254 additions & 214 deletions

File tree

src/utils/debounce.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
import Vue from 'vue'
7+
import { INPUT_DEBOUNCE_MS } from '../models/Constants.js'
8+
9+
/**
10+
*
11+
* @param {Function} fn The function to debounce
12+
* @param {number} delay delay in milliseconds
13+
*/
14+
function debounce(fn, delay) {
15+
let timeoutId = null
16+
return function () {
17+
clearTimeout(timeoutId)
18+
const args = arguments
19+
const that = this
20+
timeoutId = setTimeout(function () {
21+
fn.apply(that, args)
22+
}, delay)
23+
}
24+
}
25+
26+
/**
27+
*
28+
* @param {any} initialValue Initial value
29+
* @param {number} delay delay in milliseconds
30+
*/
31+
export function debouncedProperty(initialValue, delay = INPUT_DEBOUNCE_MS) {
32+
const observable = Vue.observable({ value: initialValue })
33+
return {
34+
get() {
35+
return observable.value
36+
},
37+
set: debounce(function (newValue) {
38+
observable.value = newValue
39+
}, delay),
40+
}
41+
}

0 commit comments

Comments
 (0)