File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments