Skip to content

Commit

Permalink
refactor config-node method
Browse files Browse the repository at this point in the history
  • Loading branch information
VasilyStrelyaev committed Oct 16, 2024
1 parent 5148926 commit 0edb1c0
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions packages/devextreme-react/src/core/configuration/config-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ interface NodeConfigBuilder {
configCollectionMaps: Record<string, Record<string, number>>;
attachChildNode: (name: string, childNode: IConfigNode) => void;
attachTemplate: (template: ITemplate) => void;
getConfigCollectionData: (name: string) => [IConfigNode[], Record<string, number>];
updateAnonymousTemplates: (hasTemplateRendered: boolean) => void;
addCollectionNode: (name: string, collectionNode: IConfigNode, collectionNodeKey: number) => void;
wrapTemplate: (template: ITemplate) => ITemplate;
Expand Down Expand Up @@ -73,22 +74,22 @@ const createConfigBuilder: (
},
configCollectionMaps: {},

getConfigCollectionData(name: string) {
if (!this.node.configCollections[name]) {
this.node.configCollections[name] = [];
this.configCollectionMaps[name] = {};
}

return [this.node.configCollections[name], this.configCollectionMaps[name]];
},

attachChildNode(name, childNode) {
childNode.parentNode = this.node;
this.node.configs[name] = childNode;
},

addCollectionNode(name, collectionNode, collectionNodeKey) {
let collection = this.node.configCollections[name];
let collectionMap = this.configCollectionMaps[name];

if (!collection) {
collection = [];
this.node.configCollections[name] = collection;
collectionMap = {};
this.configCollectionMaps[name] = collectionMap;
}

const [collection, collectionMap] = this.getConfigCollectionData(name);
const itemIndex = collectionMap[collectionNodeKey] ?? collection.length;
collectionNode.index = itemIndex;
collectionNode.parentNode = this.node;
Expand Down

0 comments on commit 0edb1c0

Please sign in to comment.