Skip to content

Commit f7978f2

Browse files
committed
feat: 🎸 added node update support to TreeStateModifiers
1 parent 60aa935 commit f7978f2

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ export interface TreeState {
150150
}
151151

152152
export interface TreeStateModifiers {
153-
editNodeAt: (state: State, index: number, setNode: (oldNode: Node) => Node) => State;
153+
editNodeAt: (state: State, index: number, updateNode: ((oldNode: Node) => Node) | Node) => State;
154154
deleteNodeAt: (state: State, index: number) => State;
155155
}
156156

src/state/TreeStateModifiers.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ export default class TreeStateModifiers {
2121
* Given a state, finds a node at a certain row index.
2222
* @param {State} state - The current state
2323
* @param {number} index - The visible row index
24-
* @param {setNode} setNode - A function to update the node
24+
* @param {setNode|Node} nodeUpdate - A function to update the node
2525
* @return {State} An internal state representation
2626
*/
27-
static editNodeAt = (state, index, setNode) => {
27+
static editNodeAt = (state, index, nodeUpdate) => {
2828
const node = TreeState.getNodeAt(state, index);
29-
const updatedNode = setNode(node);
29+
const updatedNode = typeof nodeUpdate === 'function' ? nodeUpdate(node) : nodeUpdate;
3030
const flattenedTree = [...state.flattenedTree];
3131
const flattenedNodeMap = flattenedTree[index];
3232
const parents = flattenedNodeMap.slice(0, flattenedNodeMap.length - 1);

0 commit comments

Comments
 (0)