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 patterns: Map<string, IPattern> = new Map(configuration.Patterns.map(pattern => [pattern.id, pattern]));
|
||||
const containerOrPattern = GetPattern(patternId, configs, patterns);
|
||||
const pattern = containerOrPattern as IPattern | IAvailableContainer;
|
||||
|
||||
if (!('children' in pattern)) {
|
||||
// containerOrPattern is not a pattern but a container
|
||||
const container = containerOrPattern as IAvailableContainer;
|
||||
// Add Container
|
||||
AddNewContainerToParent(
|
||||
container,
|
||||
configuration,
|
||||
containers,
|
||||
newContainer,
|
||||
0, 0,
|
||||
newCounters,
|
||||
symbols
|
||||
);
|
||||
if (containerOrPattern === undefined) {
|
||||
console.warn(`[InitializeChildrenWithPattern] PatternId ${patternId} was neither found as Pattern nor as IAvailableContainer`);
|
||||
return;
|
||||
}
|
||||
|
||||
// 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
|
||||
*/
|
||||
function BuildPatterns(
|
||||
rootPattern: IPattern,
|
||||
rootPattern: ContainerOrPattern,
|
||||
newContainer: ContainerModel,
|
||||
configuration: IConfiguration,
|
||||
containers: Map<string, IContainerModel>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue