Skip to content

Commit 8020f38

Browse files
author
Jerry Bruwes
committed
modified: index.ts
1 parent a331988 commit 8020f38

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

index.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import type { Reactive } from "vue";
2-
1+
import { toReactive } from "@vueuse/core";
32
import { v4 } from "uuid";
43
import { computed, isReactive, reactive } from "vue";
54

65
/* -------------------------------------------------------------------------- */
76

87
export default (
9-
tree: Reactive<Record<string, unknown>[]> | Record<string, unknown>[],
8+
tree: Record<string, unknown>[],
109
{
1110
branch: keyBranch = "branch",
1211
children: keyChildren = "children",
@@ -77,14 +76,16 @@ export default (
7776

7877
const leaves = computed(() => getLeaves({ value }));
7978

80-
const atlas = computed(() =>
81-
Object.fromEntries(
82-
leaves.value.map((leaf) => [leaf[keyId] as string, leaf]),
79+
const atlas: Record<string, Record<string, unknown>> = toReactive(
80+
computed(() =>
81+
Object.fromEntries(
82+
leaves.value.map((leaf) => [leaf[keyId] as string, leaf]),
83+
),
8384
),
8485
);
8586

8687
const add = (pId: string) => {
87-
const the = atlas.value[pId];
88+
const the = atlas[pId];
8889
if (the) {
8990
const children = the[keyChildren] as
9091
| Record<string, unknown>[]
@@ -108,7 +109,7 @@ export default (
108109
return undefined;
109110
},
110111
down = (pId: string) => {
111-
const the = atlas.value[pId];
112+
const the = atlas[pId];
112113
if (the) {
113114
const index = the[keyIndex] as number,
114115
nextIndex = index + 1,
@@ -125,7 +126,7 @@ export default (
125126
}
126127
},
127128
left = (pId: string) => {
128-
const the = atlas.value[pId];
129+
const the = atlas[pId];
129130
if (the) {
130131
const parent = the[keyParent] as Record<string, unknown> | undefined;
131132
if (parent?.[keyParent]) {
@@ -145,7 +146,7 @@ export default (
145146
return undefined;
146147
},
147148
remove = (pId: string) => {
148-
const the = atlas.value[pId];
149+
const the = atlas[pId];
149150
if (the) {
150151
const parent = the[keyParent] as Record<string, unknown> | undefined;
151152
if (parent) {
@@ -164,7 +165,7 @@ export default (
164165
return undefined;
165166
},
166167
right = (pId: string) => {
167-
const the = atlas.value[pId];
168+
const the = atlas[pId];
168169
if (the) {
169170
const prev = the[keyPrev] as Record<string, unknown> | undefined;
170171
if (prev) {
@@ -184,7 +185,7 @@ export default (
184185
return undefined;
185186
},
186187
up = (pId: string) => {
187-
const the = atlas.value[pId];
188+
const the = atlas[pId];
188189
if (the) {
189190
const index = the[keyIndex] as number,
190191
prevIndex = index - 1,

0 commit comments

Comments
 (0)