parent: string;
active: boolean;
selected: boolean;
+ initialState?: boolean;
expanded: boolean;
status: TreeNodeStatus;
}
export const mapTreeValues = <T, R>(mapFn: (value: T) => R) => (tree: Tree<T>): Tree<R> =>
getNodeDescendantsIds('')(tree)
.map(id => getNode(id)(tree))
+ .filter(node => !!node)
.map(mapNodeValue(mapFn))
.reduce((newTree, node) => setNode(node)(newTree), createTree<R>());
...data,
});
+export const getTreeDirty = (id: string) => <T>(tree: Tree<T>): boolean => {
+ const node = getNode(id)(tree);
+ const children = getNodeDescendants(id)(tree);
+ return (node
+ && node.initialState !== undefined
+ && node.selected !== node.initialState
+ )
+ || children.some(child =>
+ child.initialState !== undefined
+ && child.selected !== child.initialState
+ );
+}
+
const toggleDescendantsSelection = (id: string) => <T>(tree: Tree<T>) => {
const node = getNode(id)(tree);
if (node) {
return tree;
};
-
const mapNodeValue = <T, R>(mapFn: (value: T) => R) => (node: TreeNode<T>): TreeNode<R> =>
({ ...node, value: mapFn(node.value) });