Skip to content

Commit a634c7f

Browse files
committed
Add internal debounce to the input wrapper
This adds a new `debounce` prop to the input-wrapper which allows proper internal debouncing.
1 parent 65d5c62 commit a634c7f

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/FeathersVuexInputWrapper.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import _debounce from 'lodash/debounce'
2+
13
export default {
24
name: 'FeathersVuexInputWrapper',
35
props: {
@@ -8,6 +10,10 @@ export default {
810
prop: {
911
type: String,
1012
required: true
13+
},
14+
debounce: {
15+
type: Number,
16+
default: 0
1117
}
1218
},
1319
data: () => ({
@@ -18,6 +24,14 @@ export default {
1824
return this.clone || this.item
1925
}
2026
},
27+
watch: {
28+
debounce: {
29+
handler(wait) {
30+
this.debouncedHandler = _debounce(this.handler, wait)
31+
},
32+
immediate: true
33+
}
34+
},
2135
methods: {
2236
createClone(e) {
2337
this.clone = this.item.clone()
@@ -28,6 +42,7 @@ export default {
2842
})
2943
},
3044
handler(e, callback) {
45+
debugger
3146
if (!this.clone) {
3247
this.createClone()
3348
}
@@ -45,7 +60,9 @@ export default {
4560
}
4661
},
4762
render() {
48-
const { current, prop, createClone, handler } = this
63+
const { current, prop, createClone } = this
64+
const handler = this.debounce ? this.debouncedHandler : this.handler
65+
4966
return this.$scopedSlots.default({ current, prop, createClone, handler })
5067
}
5168
}

0 commit comments

Comments
 (0)