Skip to content

Commit d44cc4b

Browse files
committed
Add debounce to addData method
1 parent 3ca29a5 commit d44cc4b

9 files changed

+54
-29
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2727
2828
-->
2929

30+
## [v0.3.3] - 2021-02-22
31+
32+
- Added debounce for addData method so that only the last call is processed
33+
3034
## [v0.3.1] - 2020-10-16
3135

3236
- Added watcher for options and refresh the chart once it changes

dist/Vue2LeafletHeightGraph.common.js

Lines changed: 15 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/Vue2LeafletHeightGraph.common.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/Vue2LeafletHeightGraph.umd.js

Lines changed: 15 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/Vue2LeafletHeightGraph.umd.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/Vue2LeafletHeightGraph.umd.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/Vue2LeafletHeightGraph.umd.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue2-leaflet-height-graph",
3-
"version": "0.3.1",
3+
"version": "0.3.2",
44
"description": "Leaflet.Heightgraph plugin extension for vue2-leaflet package",
55
"main": "dist/Vue2LeafletHeightGraph.umd.min.js",
66
"scripts": {

src/vue2-leaflet-height-graph.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ export default {
1515
breakpointsOrder: ['xs', 'sm', 'md', 'lg', 'xl'],
1616
defaultParser: 'geoJson',
1717
defaultPosition: 'bottomright',
18-
controlRef: null
18+
controlRef: null,
19+
addDataDebounceTimeoutId: null
1920
}
2021
},
2122
components: {
@@ -79,13 +80,19 @@ export default {
7980
* @param {Object} data
8081
*/
8182
addData (data) {
82-
try {
83-
let p = Object.keys(this.availableParsers).includes(this.optionsGetter.parser) ? this.optionsGetter.parser : 'noParser'
84-
this.hgInstance.addData(this.availableParsers[p](data))
85-
} catch (e) {
86-
let error = `Unable to parse data using ${this.optionsGetter.parser} parser \n ${e.message}`
87-
console.error(error)
88-
}
83+
clearTimeout(this.addDataDebounceTimeoutId)
84+
const context = this
85+
86+
// Make sure that the changes in the data are debounced
87+
this.addDataDebounceTimeoutId = setTimeout(function () {
88+
try {
89+
let p = Object.keys(context.availableParsers).includes(context.optionsGetter.parser) ? context.optionsGetter.parser : 'noParser'
90+
context.hgInstance.addData(context.availableParsers[p](data))
91+
} catch (e) {
92+
let error = `Unable to parse data using ${context.optionsGetter.parser} parser \n ${e.message}`
93+
console.error(error)
94+
}
95+
}, 200)
8996
},
9097
/**
9198
* When the window size changes

0 commit comments

Comments
 (0)