UNPKG

@visactor/openinula-vchart

Version:

The openinula version of VChart 4.x

26 lines (22 loc) 1.27 kB
import React, { useContext, useEffect } from "openinula"; import { pickWithout } from "@visactor/vutils"; import RootChartContext from "../context/chart"; import { bindEventsToChart } from "../eventsUtils"; export const createComponent = (componentName, specName, supportedEvents, isSingle) => { const ignoreKeys = [ "id", "updateId", "componentId" ], 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