Skip to content
This repository was archived by the owner on Feb 15, 2022. It is now read-only.

Commit a122815

Browse files
authored
fix hot-reloading of bars (#14)
1 parent 8ff7100 commit a122815

File tree

8 files changed

+3798
-2495
lines changed

8 files changed

+3798
-2495
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ You can pass an array of objects as data value, and give your labels a `title`.
146146
</bars>
147147
```
148148

149+
## On-the-fly reloading
150+
151+
Make sure you use pass the same variable for your `data` as for the `key`, this will make sure Vue recognizes changes to your data array,
152+
and consequently forces a reload of the instance.
153+
149154
## TODO
150155
- Unit test
151156

dist/vue-bars.common.js

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -184,26 +184,6 @@ var Bars$1 = {
184184
}
185185
},
186186

187-
watch: {
188-
data: {
189-
immediate: true,
190-
handler: function handler (val) {
191-
var this$1 = this;
192-
193-
this.$nextTick(function () {
194-
if (this$1.$isServer || !this$1.$refs.path || !this$1.autoDraw) {
195-
return
196-
}
197-
198-
var path = this$1.$refs.path.$el;
199-
200-
path.style.transform = 'none';
201-
path.style.transform = "scale(1,-1) translate(0,-" + (this$1.$refs.path.boundary.maxY) + ")";
202-
});
203-
}
204-
}
205-
},
206-
207187
render: function render (h) {
208188
if (!this.data || this.data.length < 2) { return }
209189
var ref = this;

dist/vue-bars.esm.js

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -182,26 +182,6 @@ var Bars$1 = {
182182
}
183183
},
184184

185-
watch: {
186-
data: {
187-
immediate: true,
188-
handler: function handler (val) {
189-
var this$1 = this;
190-
191-
this.$nextTick(function () {
192-
if (this$1.$isServer || !this$1.$refs.path || !this$1.autoDraw) {
193-
return
194-
}
195-
196-
var path = this$1.$refs.path.$el;
197-
198-
path.style.transform = 'none';
199-
path.style.transform = "scale(1,-1) translate(0,-" + (this$1.$refs.path.boundary.maxY) + ")";
200-
});
201-
}
202-
}
203-
},
204-
205185
render: function render (h) {
206186
if (!this.data || this.data.length < 2) { return }
207187
var ref = this;

dist/vue-bars.js

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -188,26 +188,6 @@ var Bars$1 = {
188188
}
189189
},
190190

191-
watch: {
192-
data: {
193-
immediate: true,
194-
handler: function handler (val) {
195-
var this$1 = this;
196-
197-
this.$nextTick(function () {
198-
if (this$1.$isServer || !this$1.$refs.path || !this$1.autoDraw) {
199-
return
200-
}
201-
202-
var path = this$1.$refs.path.$el;
203-
204-
path.style.transform = 'none';
205-
path.style.transform = "scale(1,-1) translate(0,-" + (this$1.$refs.path.boundary.maxY) + ")";
206-
});
207-
}
208-
}
209-
},
210-
211191
render: function render (h) {
212192
if (!this.data || this.data.length < 2) { return }
213193
var ref = this;

dist/vue-bars.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.

docs/home.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<h1>Vue Bars</h1>
66
<p> Simple, elegant spark bars for Vue.js</p>
77
<bars
8+
:key="data"
89
:data="data"
910
:gradient="gradient"
1011
:barWidth="5"
@@ -29,6 +30,7 @@
2930
this.data = [1, 2, 5, 9, 5, 10, 3, 5, 8, 12, 1, 8, 2, 9, 10, 2, 9, 4, 5, 6, 7, 3, 2, 3, 5]
3031
this.gradient = ['#ffbe88', '#ff93df']
3132
this.code = hanabi(`<bars
33+
:key="reference-to-your-var"
3234
:data="[1, 2, 5, 9, 5, 10, 3, 5, 8, 12, 1, 8, 2, 9, 10, 2, 9, 4, 5, 6, 7, 3, 2, 3, 5]"
3335
:gradient="['#ffbe88', '#ff93df']"
3436
:barWidth="5"

src/components/bars.js

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,6 @@ export default {
3737
}
3838
},
3939

40-
watch: {
41-
data: {
42-
immediate: true,
43-
handler (val) {
44-
this.$nextTick(() => {
45-
if (this.$isServer || !this.$refs.path || !this.autoDraw) {
46-
return
47-
}
48-
49-
const path = this.$refs.path.$el
50-
51-
path.style.transform = 'none'
52-
path.style.transform = `scale(1,-1) translate(0,-${this.$refs.path.boundary.maxY})`
53-
})
54-
}
55-
}
56-
},
57-
5840
render (h) {
5941
if (!this.data || this.data.length < 2) return
6042
const { width, height, padding } = this

0 commit comments

Comments
 (0)