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/018eef1 below:

minor code optimizations to filter debouncing (#4167) · bootstrap-vue/bootstrap-vue@018eef1 · GitHub

File tree Expand file treeCollapse file tree 2 files changed

+25

-16

lines changed

Filter options

Expand file treeCollapse file tree 2 files changed

+25

-16

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

@@ -96,21 +96,18 @@ export default {

96 96

// We need a deep watcher in case the user passes

97 97

// an object when using `filter-function`

98 98

deep: true,

99 -

handler(newFilter, oldFilter) {

99 +

handler(newCriteria, oldCriteria) {

100 100

const timeout = this.computedFilterDebounce

101 -

if (this.$_filterTimer) {

102 -

clearTimeout(this.$_filterTimer)

103 -

this.$_filterTimer = null

104 -

}

105 -

if (timeout) {

101 +

clearTimeout(this.$_filterTimer)

102 +

this.$_filterTimer = null

103 +

if (timeout && timeout > 0) {

106 104

// If we have a debounce time, delay the update of `localFilter`

107 105

this.$_filterTimer = setTimeout(() => {

108 -

this.$_filterTimer = null

109 -

this.localFilter = this.filterSanitize(this.filter)

106 +

this.localFilter = this.filterSanitize(newCriteria)

110 107

}, timeout)

111 108

} else {

112 109

// Otherwise, immediately update `localFilter` with `newFilter` value

113 -

this.localFilter = this.filterSanitize(newFilter)

110 +

this.localFilter = this.filterSanitize(newCriteria)

114 111

}

115 112

}

116 113

},

@@ -154,12 +151,9 @@ export default {

154 151

this.isFiltered = Boolean(this.localFilter)

155 152

})

156 153

},

157 -

beforeDestroy() {

158 -

/* istanbul ignore next */

159 -

if (this.$_filterTimer) {

160 -

clearTimeout(this.$_filterTimer)

161 -

this.$_filterTimer = null

162 -

}

154 +

beforeDestroy() /* istanbul ignore next */ {

155 +

clearTimeout(this.$_filterTimer)

156 +

this.$_filterTimer = null

163 157

},

164 158

methods: {

165 159

filterSanitize(criteria) {

Original file line number Diff line number Diff line change

@@ -238,6 +238,7 @@ describe('table > filtering', () => {

238 238 239 239

it('filter debouncing works', async () => {

240 240

jest.useFakeTimers()

241 +

let lastFilterTimer = null

241 242

const wrapper = mount(BTable, {

242 243

propsData: {

243 244

fields: testFields,

@@ -254,6 +255,7 @@ describe('table > filtering', () => {

254 255

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

255 256

expect(wrapper.emitted('input')[0][0]).toEqual(testItems)

256 257

expect(wrapper.vm.$_filterTimer).toBe(null)

258 +

lastFilterTimer = wrapper.vm.$_filterTimer

257 259 258 260

// Set filter to a single character

259 261

wrapper.setProps({

@@ -262,6 +264,9 @@ describe('table > filtering', () => {

262 264

await waitNT(wrapper.vm)

263 265

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

264 266

expect(wrapper.vm.$_filterTimer).not.toBe(null)

267 +

expect(wrapper.vm.$_filterTimer).not.toEqual(lastFilterTimer)

268 +

lastFilterTimer = wrapper.vm.$_filterTimer

269 +

expect(wrapper.vm.localFilter).not.toEqual('1')

265 270 266 271

// Change filter

267 272

wrapper.setProps({

@@ -270,12 +275,17 @@ describe('table > filtering', () => {

270 275

await waitNT(wrapper.vm)

271 276

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

272 277

expect(wrapper.vm.$_filterTimer).not.toBe(null)

278 +

expect(wrapper.vm.$_filterTimer).not.toEqual(lastFilterTimer)

279 +

lastFilterTimer = wrapper.vm.$_filterTimer

280 +

expect(wrapper.vm.localFilter).not.toEqual('z')

273 281 274 282

jest.runTimersToTime(101)

275 283

await waitNT(wrapper.vm)

276 284

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

277 285

expect(wrapper.emitted('input')[1][0]).toEqual([testItems[2]])

278 -

expect(wrapper.vm.$_filterTimer).toBe(null)

286 +

expect(wrapper.vm.$_filterTimer).toEqual(lastFilterTimer)

287 +

lastFilterTimer = wrapper.vm.$_filterTimer

288 +

expect(wrapper.vm.localFilter).toEqual('z')

279 289 280 290

// Change filter

281 291

wrapper.setProps({

@@ -284,6 +294,10 @@ describe('table > filtering', () => {

284 294

await waitNT(wrapper.vm)

285 295

expect(wrapper.vm.$_filterTimer).not.toBe(null)

286 296

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

297 +

expect(wrapper.vm.$_filterTimer).not.toEqual(lastFilterTimer)

298 +

lastFilterTimer = wrapper.vm.$_filterTimer

299 +

expect(wrapper.vm.localFilter).not.toEqual('1')

300 +

expect(wrapper.vm.localFilter).toEqual('z')

287 301 288 302

// Change filter-debounce to no debouncing

289 303

wrapper.setProps({

@@ -295,6 +309,7 @@ describe('table > filtering', () => {

295 309

// Should immediately filter the items

296 310

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

297 311

expect(wrapper.emitted('input')[2][0]).toEqual([testItems[1]])

312 +

expect(wrapper.vm.localFilter).toEqual('1')

298 313 299 314

wrapper.destroy()

300 315

})

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