Skip to content

Commit 384dc92

Browse files
authored
Fixed number of times update will get called (#39) (#40)
1 parent 4ad4296 commit 384dc92

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

example/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ var chart = new Vue({
2727
el: '#chart1',
2828
components: { fusioncharts: vFC },
2929
data: {
30+
counter: 0,
3031
chartType: 'Pie2D',
3132
pieDataSource: {
3233
chart: {
@@ -104,7 +105,7 @@ var chart = new Vue({
104105
methods: {
105106
changeFirstChartAttr: function() {
106107
// let dataSource = Object.assign({}, this.pieDataSource);
107-
this.chartDs.chart.caption = 'Changed to something else';
108+
// this.chartDs.chart.caption = 'Changed to something else';
108109
this.chartDs.data[2].value = this.getRandomNumber();
109110
this.chartDs.data[1].value = this.getRandomNumber();
110111
// this.pieDataSource = dataSource;
@@ -116,7 +117,7 @@ var chart = new Vue({
116117
},
117118
getRandomNumber: function() {
118119
var max = 5,
119-
min = 1;
120+
min = 2;
120121
return Math.round((max - min) * Math.random() + min);
121122
}
122123
},

src/vue-fusioncharts-component.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -145,20 +145,24 @@ export default (FC, ...options) => {
145145
deep: true
146146
},
147147
'datasource.data': {
148-
handler: function() {
149-
this.chartObj.setChartData(
150-
this.datasource || this.dataSource,
151-
this.dataFormat || this.dataformat
152-
);
148+
handler: function(newVal, prevVal) {
149+
if (newVal !== prevVal) {
150+
this.chartObj.setChartData(
151+
this.datasource || this.dataSource,
152+
this.dataFormat || this.dataformat
153+
);
154+
}
153155
},
154156
deep: false
155157
},
156158
'dataSource.data': {
157-
handler: function() {
158-
this.chartObj.setChartData(
159-
this.datasource || this.dataSource,
160-
this.dataFormat || this.dataformat
161-
);
159+
handler: function(newVal, prevVal) {
160+
if (newVal !== prevVal) {
161+
this.chartObj.setChartData(
162+
this.datasource || this.dataSource,
163+
this.dataFormat || this.dataformat
164+
);
165+
}
162166
},
163167
deep: false
164168
}
@@ -182,6 +186,7 @@ export default (FC, ...options) => {
182186
cloneDataSource(ds, 'diff')
183187
);
184188
if (strPrevClonedDataSource !== strCurrClonedDataSource) {
189+
this.prevDataSource = cloneDataSource(ds, 'diff');
185190
this.chartObj.setChartData(ds, this.dataFormat || this.dataformat);
186191
}
187192
}

0 commit comments

Comments
 (0)