Skip to content

Commit

Permalink
feat(events): Add events to reactiveMixins (#389)
Browse files Browse the repository at this point in the history
* feat(events): Add events to reactiveMixins

This will resolve #382

* docs(reactive): Add events section to docs
  • Loading branch information
apertureless committed Aug 4, 2018
1 parent fc646d8 commit 67e8e4d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
12 changes: 12 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,18 @@ data () {
}
```

### Events

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:

- `chart:render` - if the mixin performs a complete rerender
- `chart:destroy` - if the mixin deletes the chart object instance
- `chart:update` - if the mixin performs an update instead of a re-render
- `labels:update` - if new labels were set
- `xlabels:update` if new xLabels were set
- `ylabels:update` - if new yLabels were set


### Example

**LineChart.js**
Expand Down
8 changes: 8 additions & 0 deletions src/mixins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,33 @@ function dataHandler (newData, oldData) {

if (newData.hasOwnProperty('labels')) {
chart.data.labels = newData.labels
this.$emit('labels:update')
}
if (newData.hasOwnProperty('xLabels')) {
chart.data.xLabels = newData.xLabels
this.$emit('xlabels:update')
}
if (newData.hasOwnProperty('yLabels')) {
chart.data.yLabels = newData.yLabels
this.$emit('ylabels:update')
}
chart.update()
this.$emit('chart:update')
} else {
if (chart) {
chart.destroy()
this.$emit('chart:destroy')
}
this.renderChart(this.chartData, this.options)
this.$emit('chart:render')
}
} else {
if (this.$data._chart) {
this.$data._chart.destroy()
this.$emit('chart:destroy')
}
this.renderChart(this.chartData, this.options)
this.$emit('chart:render')
}
}

Expand Down

0 comments on commit 67e8e4d

Please sign in to comment.