devextreme-react
Version:
DevExtreme React UI and Visualization Components
62 lines (60 loc) • 2.47 kB
JavaScript
/*!
* devextreme-react
* Version: 24.2.6
* Build date: Mon Mar 17 2025
*
* Copyright (c) 2012 - 2025 Developer Express Inc. ALL RIGHTS RESERVED
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file in the root of the project for details.
*
* https://github.com/DevExpress/devextreme-react
*/
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.useOptionScanning = void 0;
const react_1 = require("react");
const utils_1 = require("./configuration/utils");
const config_node_1 = require("./configuration/config-node");
const contexts_1 = require("./contexts");
function useOptionScanning(optionElement, getHasTemplate, parentUpdateToken, parentType) {
const parentContext = (0, react_1.useContext)(contexts_1.NestedOptionContext);
const { parentFullName, } = parentContext;
const updateToken = Symbol('update token');
const configBuilder = (0, config_node_1.createConfigBuilder)(optionElement, parentFullName);
const childComponentCounter = (0, react_1.useRef)(0);
const context = {
parentExpectedChildren: optionElement.descriptor.expectedChildren,
parentFullName: (0, utils_1.mergeNameParts)(parentFullName, optionElement.descriptor.name),
parentType,
treeUpdateToken: updateToken,
getOptionComponentKey: () => {
childComponentCounter.current += 1;
return childComponentCounter.current;
},
onNamedTemplateReady: (template, childUpdateToken) => {
if (childUpdateToken !== updateToken) {
return;
}
if (template) {
configBuilder.addTemplate(template);
}
},
onChildOptionsReady: (childConfigNode, childDescriptor, childUpdateToken, childComponentKey) => {
if (childUpdateToken !== updateToken) {
return;
}
const { isCollection, name } = childDescriptor;
if (isCollection) {
configBuilder.addCollectionNode(name, childConfigNode, childComponentKey);
return;
}
configBuilder.addChildNode(name, childConfigNode);
},
};
(0, react_1.useLayoutEffect)(() => {
configBuilder.updateAnonymousTemplates(getHasTemplate());
}, [parentUpdateToken]);
return [configBuilder.node, context];
}
exports.useOptionScanning = useOptionScanning;