Skip to content

Commit 8d48ad6

Browse files
committed
refactor: rename nodesMap to kvNodes for clarity
1 parent 5ba07d8 commit 8d48ad6

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ The main composable function that transforms a JSON tree into a flat array with
5555
An object with the following properties:
5656

5757
- `nodes`: `ComputedRef<Record<string, unknown>[]>` - Computed flat array of objects
58-
- `nodesMap`: `ComputedRef<{[id: string]: Record<string, unknown>}>` - Reactive object with unique IDs as keys
58+
- `kvNodes`: `ComputedRef<{[id: string]: Record<string, unknown>}>` - Reactive object with unique IDs as keys
5959
- Manipulation methods:
6060
- `add(pId: string)`: Add an empty object to the siblings
6161
- `addChild(pId: string)`: Add an empty object to the children
@@ -107,7 +107,7 @@ const tree = [
107107
},
108108
];
109109

110-
const { nodes, nodesMap, add, down, left, remove, right, up } =
110+
const { nodes, kvNodes, add, down, left, remove, right, up } =
111111
useFlatJsonTree(tree);
112112
```
113113

@@ -183,10 +183,10 @@ Output:
183183
{ "id": 6, "name": "1.2.6" }
184184
```
185185

186-
If the ID is known, you can use `nodesMap`:
186+
If the ID is known, you can use `kvNodes`:
187187

188188
```js
189-
console.log(JSON.stringify(nodesMap.value[6]));
189+
console.log(JSON.stringify(kvNodes.value[6]));
190190
```
191191

192192
Output:

src/index.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const configurable = true,
3030
* @param [root0.prev] - Key name for prev property (default: "prev")
3131
* @param [root0.siblings] - Key name for siblings property (default:
3232
* "siblings")
33-
* @returns Object containing nodes, nodesMap and manipulation functions
33+
* @returns Object containing nodes, kvNodes and manipulation functions
3434
*/
3535
export default (
3636
tree: unObject[],
@@ -95,6 +95,7 @@ export default (
9595
},
9696
},
9797
};
98+
9899
/**
99100
* Generator function that traverses the tree and yields each node
100101
*
@@ -128,8 +129,9 @@ export default (
128129
},
129130
nodes = computed(() => [
130131
...getNodes(isReactive(tree) ? tree : reactive(tree)),
131-
]),
132-
nodesMap = computed(() =>
132+
]);
133+
134+
const kvNodes = computed(() =>
133135
Object.fromEntries(
134136
nodes.value.map((node) => [node[keyId] as string, node]),
135137
),
@@ -143,7 +145,7 @@ export default (
143145
* @returns ID of the affected node or undefined
144146
*/
145147
run = (pId: string, action: string) => {
146-
const the = nodesMap.value[pId];
148+
const the = kvNodes.value[pId];
147149
if (the) {
148150
const [root] = nodes.value,
149151
index = the[keyIndex] as number,
@@ -236,6 +238,7 @@ export default (
236238
* @returns Undefined
237239
*/
238240
down: (pId: string) => run(pId, "down"),
241+
kvNodes,
239242
/**
240243
* Moves the specified node one level up in the hierarchy, making it a
241244
* sibling of its parent
@@ -245,7 +248,6 @@ export default (
245248
*/
246249
left: (pId: string) => run(pId, "left"),
247250
nodes,
248-
nodesMap,
249251
/**
250252
* Removes the specified node from the tree
251253
*

0 commit comments

Comments
 (0)