UNPKG

@visactor/openinula-vtable

Version:

The openinula version of VTable

25 lines (21 loc) 1.24 kB
import Inula, { useContext, useEffect } from "openinula"; import { pickWithout } from "@visactor/vutils"; import RootTableContext from "../context/table"; import { bindEventsToTable } from "../eventsUtils"; export const createComponent = (componentName, optionName, supportedEvents, isSingle) => { const ignoreKeys = [ "id", "updateId", "componentId" ], notOptionKeys = supportedEvents ? Object.keys(supportedEvents).concat(ignoreKeys) : ignoreKeys, Comp = props => { const context = useContext(RootTableContext), eventsBinded = Inula.useRef(null), updateId = Inula.useRef(props.updateId); if (props.updateId !== updateId.current) { updateId.current = props.updateId; !!supportedEvents && bindEventsToTable(context.table, props, eventsBinded.current, supportedEvents) && (eventsBinded.current = props); } return useEffect((() => () => { supportedEvents && bindEventsToTable(context.table, null, eventsBinded.current, supportedEvents); }), []), null; }; return Comp.displayName = componentName, Comp.parseOption = props => ({ option: pickWithout(props, notOptionKeys), optionName: optionName, isSingle: isSingle }), Comp; };