Skip to content

Commit a9e8039

Browse files
committed
Simplify getItems and fix parent/sibling references
1 parent 53a142a commit a9e8039

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

src/index.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,8 @@ const configurable = true;
1616
/* Служебные функции */
1717
/* -------------------------------------------------------------------------- */
1818

19-
const getItems = (nodes: unObject[], node?: unObject) =>
20-
[...nodes].reverse().map((child) => ({
21-
node: child,
22-
parent: { configurable, value: node },
23-
siblings: { configurable, value: nodes },
24-
})),
19+
const getItems = (siblings: unObject[], parent?: unObject) =>
20+
[...siblings].reverse().map((node) => ({ node, parent, siblings })),
2521
uid = () => {
2622
const url = URL.createObjectURL(new Blob()),
2723
uid = url.split("/").pop() ?? crypto.randomUUID();
@@ -89,13 +85,13 @@ export default (
8985
const stack = getItems(nodes);
9086
while (stack.length) {
9187
const { node, parent, siblings } = stack.pop() ?? {};
92-
if (node && parent && siblings) {
88+
if (node) {
9389
if (node[keyParent] !== parent)
9490
Object.defineProperty(node, keyParent, {
9591
configurable,
9692
value: parent,
9793
});
98-
if (node[keySiblings] !== parent)
94+
if (node[keySiblings] !== siblings)
9995
Object.defineProperty(node, keySiblings, {
10096
configurable,
10197
value: siblings,

0 commit comments

Comments
 (0)