Skip to content

Commit 1040daf

Browse files
committed
fix: avoid vars start with $
1 parent e27927b commit 1040daf

File tree

4 files changed

+48
-42
lines changed

4 files changed

+48
-42
lines changed

README.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
[![GitHub Action](https://github.com/weizhenye/vue-highcharts/workflows/CI/badge.svg)](https://github.com/weizhenye/vue-highcharts/actions)
44
[![Coverage](https://badgen.net/codecov/c/github/weizhenye/vue-highcharts?icon=codecov)](https://codecov.io/gh/weizhenye/vue-highcharts)
5-
[![Dependencies](https://badgen.net/david/dep/weizhenye/vue-highcharts?icon=https://api.iconify.design/si-glyph:connect-2.svg?color=white)](https://david-dm.org/weizhenye/vue-highcharts)
65
[![NPM version](https://badgen.net/npm/v/vue-highcharts?icon=npm)](https://www.npmjs.com/package/vue-highcharts)
76
[![License](https://badgen.net/npm/license/vue-highcharts?icon=https://api.iconify.design/octicon:law.svg?color=white)](https://github.com/weizhenye/vue-highcharts/blob/master/LICENSE)
87
[![File size](https://badgen.net/bundlephobia/minzip/vue-highcharts?icon=https://api.iconify.design/ant-design:file-zip-outline.svg?color=white)](https://bundlephobia.com/result?p=vue-highcharts)
@@ -26,7 +25,7 @@ For **Vue 2**, please run `npm i -S vue-highcharts@0.1`, and checkout document [
2625

2726
## Usage
2827

29-
### Registering Globally
28+
### Registering globally
3029

3130
```js
3231
import { createApp } from 'vue';
@@ -41,7 +40,7 @@ app.use(VueHighcharts, { Highcharts });
4140
```
4241

4342
<details>
44-
<summary>Direct <code>&lt;script&gt;</code> Include</summary>
43+
<summary>Direct <code>&lt;script&gt;</code> include</summary>
4544

4645
```html
4746
<script src="/path/to/vue/dist/vue.global.prod.js"></script>
@@ -86,7 +85,7 @@ app.use(VueHighcharts, { Highcharts });
8685
// drilldown and solid gauge are work with <Highcharts />
8786
```
8887

89-
### Registering In Components
88+
### Registering in components
9089

9190
```vue
9291
<template>
@@ -124,7 +123,7 @@ function createHighcharts(name: ChartName, Highcharts: Highcharts): VueComponent
124123

125124
```vue
126125
<template>
127-
<Highcharts ref="$highcharts" :options="chartOptions" />
126+
<Highcharts ref="highchartsRef" :options="chartOptions" />
128127
<Highstock :options="stockOptions" />
129128
<Highmaps :options="mapsOptions" />
130129
<HighchartsGantt :options="ganttOptions" />
@@ -135,12 +134,18 @@ import { ref, onMounted } from 'vue';
135134
136135
export default {
137136
setup() {
138-
const $highcharts = ref(null);
137+
const highchartsRef = ref(null);
139138
onMounted(() => {
140139
// access the `chart` instance with template refs
141-
const { chart } = $highcharts.value;
140+
const { chart } = highchartsRef.value;
142141
});
143-
return { $highcharts };
142+
return {
143+
highchartsRef,
144+
chartOptions: {},
145+
stockOptions: {},
146+
mapsOptions: {},
147+
ganttOptions: {},
148+
};
144149
},
145150
};
146151
</script>

index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const ctors = {
88
};
99

1010
function render() {
11-
return h('div', { ref: '$highcharts' });
11+
return h('div', { ref: 'highchartsRef' });
1212
}
1313

1414
function createHighcharts(name, Highcharts) {
@@ -26,19 +26,19 @@ function createHighcharts(name, Highcharts) {
2626
props: ['options'],
2727
render,
2828
setup(props) {
29-
const $highcharts = ref(null);
29+
const highchartsRef = ref(null);
3030
const chart = ref(null);
3131
onMounted(() => {
3232
watchEffect(() => {
33-
chart.value = ctor($highcharts.value, props.options);
33+
chart.value = ctor(highchartsRef.value, props.options);
3434
});
3535
});
3636
onBeforeUnmount(() => {
37-
if ($highcharts.value) {
37+
if (highchartsRef.value) {
3838
chart.value.destroy();
3939
}
4040
});
41-
return { $highcharts, chart };
41+
return { highchartsRef, chart };
4242
},
4343
};
4444
}

package.json

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"description": "Highcharts component for Vue",
55
"main": "dist/vue-highcharts.js",
66
"module": "index.js",
7+
"sideEffects": false,
78
"files": [
89
"dist",
910
"index.js"
@@ -40,16 +41,16 @@
4041
"vue": ">=3"
4142
},
4243
"devDependencies": {
43-
"@babel/core": "^7.10.3",
44-
"@babel/preset-env": "^7.10.3",
45-
"@rollup/plugin-babel": "^5.0.4",
46-
"eslint": "^7.3.1",
44+
"@babel/core": "^7.11.6",
45+
"@babel/preset-env": "^7.11.5",
46+
"@rollup/plugin-babel": "^5.2.1",
47+
"eslint": "^7.9.0",
4748
"eslint-config-airbnb-base": "^14.2.0",
48-
"eslint-plugin-import": "^2.21.2",
49-
"highcharts": "^8.1.2",
50-
"jest": "^26.1.0",
51-
"rollup": "^2.18.0",
52-
"rollup-plugin-terser": "^6.1.0",
53-
"vue": "^3.0.0-beta.15"
49+
"eslint-plugin-import": "^2.22.0",
50+
"highcharts": "^8.2.0",
51+
"jest": "^26.4.2",
52+
"rollup": "^2.27.1",
53+
"rollup-plugin-terser": "^7.0.2",
54+
"vue": "^3.0.0"
5455
}
5556
}

test/test.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,49 +21,49 @@ describe('vue-highcharts', () => {
2121
const root = createComponent({
2222
template,
2323
setup() {
24-
return { $chart: ref(null) };
24+
return { chartRef: ref(null) };
2525
},
2626
});
27-
expect(root.$chart.$highcharts.querySelector('.highcharts-root')).toBeDefined();
27+
expect(root.chartRef.highchartsRef.querySelector('.highcharts-root')).toBeDefined();
2828
}
2929

3030
it('should support <Highcharts /> component', () => {
31-
checkComponent('<Highcharts ref="$chart" :options="{}" />');
31+
checkComponent('<Highcharts ref="chartRef" :options="{}" />');
3232
});
3333

3434
it('should support <Highstock /> component', () => {
35-
checkComponent('<Highstock ref="$chart" :options="{}" />');
35+
checkComponent('<Highstock ref="chartRef" :options="{}" />');
3636
});
3737

3838
it('should support <Highmaps /> component', () => {
39-
checkComponent('<Highmaps ref="$chart" :options="{}" />');
39+
checkComponent('<Highmaps ref="chartRef" :options="{}" />');
4040
});
4141

4242
it('should support <HighchartsGantt /> component', () => {
43-
checkComponent('<HighchartsGantt ref="$chart" :options="{}" />');
43+
checkComponent('<HighchartsGantt ref="chartRef" :options="{}" />');
4444
});
4545

4646
it('can access the `chart` instance via template refs', () => {
4747
const root = createComponent({
48-
template: '<Highcharts ref="$chart" :options="{}" />',
48+
template: '<Highcharts ref="chartRef" :options="{}" />',
4949
setup() {
50-
return { $chart: ref(null) };
50+
return { chartRef: ref(null) };
5151
},
5252
});
53-
expect(root.$chart.chart).toBeDefined();
53+
expect(root.chartRef.chart).toBeDefined();
5454
});
5555

5656
it('should destroy the chart instance when vm destroyed', (done) => {
5757
let chart = null;
5858
let el = null;
5959
const app = createApp({
60-
template: '<div ref="$div"><Highcharts ref="$chart" :options="{}" /></div>',
60+
template: '<div ref="divRef"><Highcharts ref="chartRef" :options="{}" /></div>',
6161
setup() {
62-
const $div = ref(null);
63-
const $chart = ref(null);
62+
const divRef = ref(null);
63+
const chartRef = ref(null);
6464
onBeforeUnmount(() => {
65-
el = $div.value;
66-
chart = $chart.value.chart;
65+
el = divRef.value;
66+
chart = chartRef.value.chart;
6767
expect(el.querySelector('.highcharts-root')).toBeDefined();
6868
expect(chart).toBeDefined();
6969
});
@@ -74,7 +74,7 @@ describe('vue-highcharts', () => {
7474
done();
7575
});
7676
});
77-
return { $div, $chart };
77+
return { divRef, chartRef };
7878
},
7979
});
8080
app.use(VueHighcharts, { Highcharts });
@@ -84,18 +84,18 @@ describe('vue-highcharts', () => {
8484

8585
it('should watch `options`', () => {
8686
const root = createComponent({
87-
template: '<Highcharts ref="$chart" :options="options" />',
87+
template: '<Highcharts ref="chartRef" :options="options" />',
8888
setup() {
8989
return {
90-
$chart: ref(null),
90+
chartRef: ref(null),
9191
options: ref({ title: { text: 'origin' } }),
9292
};
9393
},
9494
});
95-
expect(root.$chart.chart.title.textStr).toBe('origin');
95+
expect(root.chartRef.chart.title.textStr).toBe('origin');
9696
root.options.title.text = 'changed';
9797
nextTick().then(() => {
98-
expect(root.$chart.chart.title.textStr).toBe('changed');
98+
expect(root.chartRef.chart.title.textStr).toBe('changed');
9999
});
100100
});
101101

0 commit comments

Comments
 (0)