1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Clean public interface of a normalize composite

Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com>

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
Janne Savolainen 2022-10-19 13:51:36 +03:00
parent c04adf3eff
commit 638ea2e12e
No known key found for this signature in database
GPG Key ID: 8C6CFB2FFFE8F68A

View File

@ -4,17 +4,21 @@
*/
import type { Composite } from "../get-composite";
export const normalizeComposite = <T>(
composite: Composite<T>,
previousPath: string[] = [],
): (readonly [path: string, composite: Composite<T>])[] => {
const currentPath = [...previousPath, composite.id];
export const normalizeComposite = <T>(composite: Composite<T>) => {
const _normalizeComposite = <T>(
composite: Composite<T>,
previousPath: string[] = [],
): (readonly [path: string, composite: Composite<T>])[] => {
const currentPath = [...previousPath, composite.id];
const pathAndCompositeTuple = [currentPath.join("."), composite] as const;
const pathAndCompositeTuple = [currentPath.join("."), composite] as const;
return [
pathAndCompositeTuple,
return [
pathAndCompositeTuple,
...composite.children.flatMap((x) => normalizeComposite(x, currentPath)),
];
...composite.children.flatMap((x) => _normalizeComposite(x, currentPath)),
];
};
return _normalizeComposite(composite);
};