1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-18 09:35:20 +02:00
joplin/packages/app-desktop/gui/ResizableLayout/utils/setLayoutItemProps.ts

24 lines
576 B
TypeScript
Raw Normal View History

import produce from 'immer';
import { LayoutItem } from './types';
import validateLayout from './validateLayout';
export default function setLayoutItemProps(layout: LayoutItem, key: string, props: any) {
return validateLayout(produce(layout, (draftState: LayoutItem) => {
function recurseFind(item: LayoutItem) {
if (item.key === key) {
for (const n in props) {
(item as any)[n] = props[n];
}
} else {
if (item.children) {
for (const child of item.children) {
recurseFind(child);
}
}
}
}
recurseFind(draftState);
}));
}