Skip to content

Commit

Permalink
fix(#516): suppress native events
Browse files Browse the repository at this point in the history
  • Loading branch information
Justineo committed Mar 2, 2021
1 parent 2d60a4d commit 731af39
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/ECharts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
onMounted,
onUnmounted,
h,
mergeProps,
PropType,
watchEffect,
Vue2
Expand All @@ -35,6 +36,7 @@ import {
loadingProps
} from "./composables";
import "./style.css";
import { filterObjectValue } from "./utils";

const TAG_NAME = "x-vue-echarts";

Expand All @@ -61,6 +63,7 @@ export default defineComponent({
...autoresizeProps,
...loadingProps
},
inheritAttrs: false,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
// @ts-expect-error
setup(props, { attrs, listeners }) {
Expand Down Expand Up @@ -92,6 +95,10 @@ export default defineComponent({
const initOptions = toRef(props, "initOptions");
const loadingOptions = toRef(props, "loadingOptions");

const nonEventAttrs = computed(() =>
filterObjectValue(attrs, value => typeof value !== "function")
);

function init(option?: Option) {
if (chart.value || !root.value) {
return;
Expand Down Expand Up @@ -225,6 +232,7 @@ export default defineComponent({
const exposed = {
root,
setOption,
nonEventAttrs,
...publicApi
};
Object.defineProperty(exposed, "chart", {
Expand All @@ -236,6 +244,9 @@ export default defineComponent({
return exposed;
},
render() {
return h(TAG_NAME, { class: "echarts", ref: "root" });
return h(
TAG_NAME,
mergeProps({ class: "echarts", ref: "root" }, this.nonEventAttrs)
);
}
});
16 changes: 16 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
type Attrs = {
[key: string]: unknown;
};

export function filterObjectValue(
source: Attrs,
predicate: (key: unknown) => boolean
) {
const target: Attrs = {};
for (const key in source) {
if (predicate(source[key])) {
target[key] = source[key];
}
}
return target;
}

0 comments on commit 731af39

Please sign in to comment.