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:
parent
c04adf3eff
commit
638ea2e12e
@ -4,17 +4,21 @@
|
|||||||
*/
|
*/
|
||||||
import type { Composite } from "../get-composite";
|
import type { Composite } from "../get-composite";
|
||||||
|
|
||||||
export const normalizeComposite = <T>(
|
export const normalizeComposite = <T>(composite: Composite<T>) => {
|
||||||
composite: Composite<T>,
|
const _normalizeComposite = <T>(
|
||||||
previousPath: string[] = [],
|
composite: Composite<T>,
|
||||||
): (readonly [path: string, composite: Composite<T>])[] => {
|
previousPath: string[] = [],
|
||||||
const currentPath = [...previousPath, composite.id];
|
): (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 [
|
return [
|
||||||
pathAndCompositeTuple,
|
pathAndCompositeTuple,
|
||||||
|
|
||||||
...composite.children.flatMap((x) => normalizeComposite(x, currentPath)),
|
...composite.children.flatMap((x) => _normalizeComposite(x, currentPath)),
|
||||||
];
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
return _normalizeComposite(composite);
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user