UNPKG

@visactor/openinula-vtable

Version:

The openinula version of VTable

55 lines (51 loc) 2.69 kB
"use strict"; var __createBinding = this && this.__createBinding || (Object.create ? function(o, m, k, k2) { void 0 === k2 && (k2 = k); var desc = Object.getOwnPropertyDescriptor(m, k); desc && !("get" in desc ? !m.__esModule : desc.writable || desc.configurable) || (desc = { enumerable: !0, get: function() { return m[k]; } }), Object.defineProperty(o, k2, desc); } : function(o, m, k, k2) { void 0 === k2 && (k2 = k), o[k2] = m[k]; }), __setModuleDefault = this && this.__setModuleDefault || (Object.create ? function(o, v) { Object.defineProperty(o, "default", { enumerable: !0, value: v }); } : function(o, v) { o.default = v; }), __importStar = this && this.__importStar || function(mod) { if (mod && mod.__esModule) return mod; var result = {}; if (null != mod) for (var k in mod) "default" !== k && Object.prototype.hasOwnProperty.call(mod, k) && __createBinding(result, mod, k); return __setModuleDefault(result, mod), result; }, __importDefault = this && this.__importDefault || function(mod) { return mod && mod.__esModule ? mod : { default: mod }; }; Object.defineProperty(exports, "__esModule", { value: !0 }), exports.createComponent = void 0; const openinula_1 = __importStar(require("openinula")), vutils_1 = require("@visactor/vutils"), table_1 = __importDefault(require("../context/table")), eventsUtils_1 = require("../eventsUtils"), createComponent = (componentName, optionName, supportedEvents, isSingle) => { const ignoreKeys = [ "id", "updateId", "componentId" ], notOptionKeys = supportedEvents ? Object.keys(supportedEvents).concat(ignoreKeys) : ignoreKeys, Comp = props => { const context = (0, openinula_1.useContext)(table_1.default), eventsBinded = openinula_1.default.useRef(null), updateId = openinula_1.default.useRef(props.updateId); if (props.updateId !== updateId.current) { updateId.current = props.updateId; !!supportedEvents && (0, eventsUtils_1.bindEventsToTable)(context.table, props, eventsBinded.current, supportedEvents) && (eventsBinded.current = props); } return (0, openinula_1.useEffect)((() => () => { supportedEvents && (0, eventsUtils_1.bindEventsToTable)(context.table, null, eventsBinded.current, supportedEvents); }), []), null; }; return Comp.displayName = componentName, Comp.parseOption = props => ({ option: (0, vutils_1.pickWithout)(props, notOptionKeys), optionName: optionName, isSingle: isSingle }), Comp; }; exports.createComponent = createComponent; //# sourceMappingURL=base-component.js.map