@visactor/react-vchart
Version:
The react version of VChart 4.x
29 lines (24 loc) • 1.4 kB
JavaScript
import React, { useContext, useEffect } from "react";
import { pickWithout } from "@visactor/vutils";
import RootChartContext from "../context/chart";
import { bindEventsToChart } from "../eventsUtils";
import { VChart } from "@visactor/vchart";
export const createComponent = (componentName, specName, supportedEvents, isSingle, registers) => {
registers && registers.length && VChart.useRegisters(registers);
const ignoreKeys = [ "updateId", "componentId", "children" ], notSpecKeys = supportedEvents ? Object.keys(supportedEvents).concat(ignoreKeys) : ignoreKeys, Comp = props => {
const context = useContext(RootChartContext), eventsBinded = React.useRef(null), updateId = React.useRef(props.updateId);
if (props.updateId !== updateId.current) {
updateId.current = props.updateId;
!!supportedEvents && bindEventsToChart(context.chart, props, eventsBinded.current, supportedEvents) && (eventsBinded.current = props);
}
return useEffect((() => () => {
supportedEvents && bindEventsToChart(context.chart, null, eventsBinded.current, supportedEvents);
}), []), null;
};
return Comp.displayName = componentName, Comp.parseSpec = props => ({
spec: pickWithout(props, notSpecKeys),
specName: specName,
isSingle: isSingle
}), Comp;
};
//# sourceMappingURL=BaseComponent.js.map