Skip to content

Commit 67e8e4d

Browse files
authored
feat(events): Add events to reactiveMixins (#389)
* feat(events): Add events to reactiveMixins This will resolve #382 * docs(reactive): Add events section to docs
1 parent fc646d8 commit 67e8e4d

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

docs/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,18 @@ data () {
190190
}
191191
```
192192

193+
### Events
194+
195+
The reactive mixins will emit events if the data changes. You can listen to them with `v:on` on the chart component. Following events are available:
196+
197+
- `chart:render` - if the mixin performs a complete rerender
198+
- `chart:destroy` - if the mixin deletes the chart object instance
199+
- `chart:update` - if the mixin performs an update instead of a re-render
200+
- `labels:update` - if new labels were set
201+
- `xlabels:update` if new xLabels were set
202+
- `ylabels:update` - if new yLabels were set
203+
204+
193205
### Example
194206

195207
**LineChart.js**

src/mixins/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,25 +42,33 @@ function dataHandler (newData, oldData) {
4242

4343
if (newData.hasOwnProperty('labels')) {
4444
chart.data.labels = newData.labels
45+
this.$emit('labels:update')
4546
}
4647
if (newData.hasOwnProperty('xLabels')) {
4748
chart.data.xLabels = newData.xLabels
49+
this.$emit('xlabels:update')
4850
}
4951
if (newData.hasOwnProperty('yLabels')) {
5052
chart.data.yLabels = newData.yLabels
53+
this.$emit('ylabels:update')
5154
}
5255
chart.update()
56+
this.$emit('chart:update')
5357
} else {
5458
if (chart) {
5559
chart.destroy()
60+
this.$emit('chart:destroy')
5661
}
5762
this.renderChart(this.chartData, this.options)
63+
this.$emit('chart:render')
5864
}
5965
} else {
6066
if (this.$data._chart) {
6167
this.$data._chart.destroy()
68+
this.$emit('chart:destroy')
6269
}
6370
this.renderChart(this.chartData, this.options)
71+
this.$emit('chart:render')
6472
}
6573
}
6674

0 commit comments

Comments
 (0)