A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/bootstrap-vue/bootstrap-vue/commit/111ca65240ab6941e2173ca44806aa0a75691c95 below:

fix debounce when value does not change (#5632) · bootstrap-vue/bootstrap-vue@111ca65 · GitHub

File tree Expand file treeCollapse file tree 2 files changed

+57

-26

lines changed

Filter options

Expand file treeCollapse file tree 2 files changed

+57

-26

lines changed Original file line number Diff line number Diff line change

@@ -871,6 +871,33 @@ describe('form-input', () => {

871 871

// `input` event should not have emitted new event

872 872

expect(wrapper.emitted('input').length).toBe(4)

873 873 874 +

$input.element.value = 'abc'

875 +

await $input.trigger('input')

876 +

expect($input.element.value).toBe('abc')

877 +

// `v-model` update event should not have emitted new event

878 +

expect(wrapper.emitted('update').length).toBe(2)

879 +

// `input` event should be emitted

880 +

expect(wrapper.emitted('input').length).toBe(5)

881 +

expect(wrapper.emitted('input')[4][0]).toBe('abc')

882 + 883 +

$input.element.value = 'abcd'

884 +

await $input.trigger('input')

885 +

expect($input.element.value).toBe('abcd')

886 +

// `v-model` update event should not have emitted new event

887 +

expect(wrapper.emitted('update').length).toBe(2)

888 +

// `input` event should be emitted

889 +

expect(wrapper.emitted('input').length).toBe(6)

890 +

expect(wrapper.emitted('input')[5][0]).toBe('abcd')

891 + 892 +

// Advance timer

893 +

jest.runOnlyPendingTimers()

894 +

// Should update the v-model

895 +

expect($input.element.value).toBe('abcd')

896 +

// `v-model` update event should not have emitted new event

897 +

expect(wrapper.emitted('update').length).toBe(2)

898 +

// `input` event should not have emitted new event

899 +

expect(wrapper.emitted('input').length).toBe(6)

900 + 874 901

wrapper.destroy()

875 902

})

876 903 Original file line number Diff line number Diff line change

@@ -161,35 +161,39 @@ export default {

161 161

if (lazy && !force) {

162 162

return

163 163

}

164 -

value = this.modifyValue(value)

165 -

if (value !== this.vModelValue) {

166 -

this.clearDebounce()

167 -

const doUpdate = () => {

164 +

// Make sure to always clear the debounce when `updateValue()`

165 +

// is called, even when the v-model hasn't changed

166 +

this.clearDebounce()

167 +

// Define the shared update logic in a method to be able to use

168 +

// it for immediate and debounced value changes

169 +

const doUpdate = () => {

170 +

value = this.modifyValue(value)

171 +

if (value !== this.vModelValue) {

168 172

this.vModelValue = value

169 173

this.$emit('update', value)

174 +

} else if (this.hasFormatter) {

175 +

// When the `vModelValue` hasn't changed but the actual input value

176 +

// is out of sync, make sure to change it to the given one

177 +

// Usually caused by browser autocomplete and how it triggers the

178 +

// change or input event, or depending on the formatter function

179 +

// https://github.com/bootstrap-vue/bootstrap-vue/issues/2657

180 +

// https://github.com/bootstrap-vue/bootstrap-vue/issues/3498

181 +

/* istanbul ignore next: hard to test */

182 +

const $input = this.$refs.input

183 +

/* istanbul ignore if: hard to test out of sync value */

184 +

if ($input && value !== $input.value) {

185 +

$input.value = value

186 +

}

170 187

}

171 -

const debounce = this.computedDebounce

172 -

// Only debounce the value update when a value greater than `0`

173 -

// is set and we are not in lazy mode or this is a forced update

174 -

if (debounce > 0 && !lazy && !force) {

175 -

this.$_inputDebounceTimer = setTimeout(doUpdate, debounce)

176 -

} else {

177 -

// Immediately update the v-model

178 -

doUpdate()

179 -

}

180 -

} else if (this.hasFormatter) {

181 -

// When the `vModelValue` hasn't changed but the actual input value

182 -

// is out of sync, make sure to change it to the given one

183 -

// Usually caused by browser autocomplete and how it triggers the

184 -

// change or input event, or depending on the formatter function

185 -

// https://github.com/bootstrap-vue/bootstrap-vue/issues/2657

186 -

// https://github.com/bootstrap-vue/bootstrap-vue/issues/3498

187 -

/* istanbul ignore next: hard to test */

188 -

const $input = this.$refs.input

189 -

/* istanbul ignore if: hard to test out of sync value */

190 -

if ($input && value !== $input.value) {

191 -

$input.value = value

192 -

}

188 +

}

189 +

// Only debounce the value update when a value greater than `0`

190 +

// is set and we are not in lazy mode or this is a forced update

191 +

const debounce = this.computedDebounce

192 +

if (debounce > 0 && !lazy && !force) {

193 +

this.$_inputDebounceTimer = setTimeout(doUpdate, debounce)

194 +

} else {

195 +

// Immediately update the v-model

196 +

doUpdate()

193 197

}

194 198

},

195 199

onInput(evt) {

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4