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 SavolainenandMikko Aspiala committed 2022-10-21 08:23:20 +03:00
1 parent c04adf3eff
commit 638ea2e12e
1 file changed
+14 -10
@@ -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);
};