Refactor and fix potential bug in InitializeChildrenWithPattern when pattern is not found in the config
This commit is contained in:
parent
5bc47d02cb
commit
b44c6fb477
1 changed files with 4 additions and 16 deletions
|
@ -301,26 +301,14 @@ function InitializeChildrenWithPattern(
|
||||||
const configs: Map<string, IAvailableContainer> = new Map(configuration.AvailableContainers.map(config => [config.Type, config]));
|
const configs: Map<string, IAvailableContainer> = new Map(configuration.AvailableContainers.map(config => [config.Type, config]));
|
||||||
const patterns: Map<string, IPattern> = new Map(configuration.Patterns.map(pattern => [pattern.id, pattern]));
|
const patterns: Map<string, IPattern> = new Map(configuration.Patterns.map(pattern => [pattern.id, pattern]));
|
||||||
const containerOrPattern = GetPattern(patternId, configs, patterns);
|
const containerOrPattern = GetPattern(patternId, configs, patterns);
|
||||||
const pattern = containerOrPattern as IPattern | IAvailableContainer;
|
|
||||||
|
|
||||||
if (!('children' in pattern)) {
|
if (containerOrPattern === undefined) {
|
||||||
// containerOrPattern is not a pattern but a container
|
console.warn(`[InitializeChildrenWithPattern] PatternId ${patternId} was neither found as Pattern nor as IAvailableContainer`);
|
||||||
const container = containerOrPattern as IAvailableContainer;
|
|
||||||
// Add Container
|
|
||||||
AddNewContainerToParent(
|
|
||||||
container,
|
|
||||||
configuration,
|
|
||||||
containers,
|
|
||||||
newContainer,
|
|
||||||
0, 0,
|
|
||||||
newCounters,
|
|
||||||
symbols
|
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// BFS over patterns
|
// BFS over patterns
|
||||||
BuildPatterns(pattern, newContainer, configuration, containers, newCounters, symbols, configs, patterns);
|
BuildPatterns(containerOrPattern, newContainer, configuration, containers, newCounters, symbols, configs, patterns);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -337,7 +325,7 @@ function InitializeChildrenWithPattern(
|
||||||
* @param patterns
|
* @param patterns
|
||||||
*/
|
*/
|
||||||
function BuildPatterns(
|
function BuildPatterns(
|
||||||
rootPattern: IPattern,
|
rootPattern: ContainerOrPattern,
|
||||||
newContainer: ContainerModel,
|
newContainer: ContainerModel,
|
||||||
configuration: IConfiguration,
|
configuration: IConfiguration,
|
||||||
containers: Map<string, IContainerModel>,
|
containers: Map<string, IContainerModel>,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue