Merged PR 216: Deprecate parent from IContainerModel for FindContainerById

This commit is contained in:
Eric Nguyen 2022-10-17 16:01:06 +00:00
parent d40cd8cf8e
commit b4eba6bb9b
19 changed files with 97 additions and 109 deletions

View file

@ -1,5 +1,4 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { FindContainerById, MakeDFSIterator } from './itertools';
import { IEditorState } from '../Interfaces/IEditorState';
import { IHistoryState } from '../Interfaces/IHistoryState';
import { IContainerModel } from '../Interfaces/IContainerModel';
@ -37,36 +36,10 @@ export function ReviveState(state: IHistoryState): void {
const containers: Array<{ Key: string, Value: IContainerModel }> = (state.containers) as any;
state.containers = new Map(containers.map(({ Key, Value }: {Key: string, Value: IContainerModel}) => [Key, Value]));
const root = FindContainerById(state.containers, state.mainContainer);
if (root === undefined) {
return;
}
// TODO: remove parent and remove this bloc of code
// TODO: See IContainerModel.ts for more detail
const it = MakeDFSIterator(root, state.containers);
for (const container of it) {
const parentId = container.properties.parentId;
if (parentId === null) {
container.parent = null;
continue;
}
const parent = FindContainerById(state.containers, parentId);
if (parent === undefined) {
continue;
}
container.parent = parent;
}
}
export function GetCircularReplacer(): (key: any, value: object | Map<string, any> | null) => object | null | undefined {
return (key: any, value: object | null) => {
if (key === 'parent') {
return;
}
if (key === 'containers') {
return [...(value as Map<string, any>).entries()]
.map(([Key, Value]: [string, any]) => ({ Key, Value }));