@@ -6,59 +6,50 @@ import { computed, isReactive, nextTick, reactive, watch } from "vue";
6
6
const configurable = true ;
7
7
export default (
8
8
tree : Record < string , unknown > [ ] ,
9
- options : Record < string , string > = { } ,
9
+ {
10
+ branch : keyBranch = "branch" ,
11
+ children : keyChildren = "children" ,
12
+ id : keyId = "id" ,
13
+ index : keyIndex = "index" ,
14
+ next : keyNext = "next" ,
15
+ parent : keyParent = "parent" ,
16
+ prev : keyPrev = "prev" ,
17
+ siblings : keySiblings = "siblings" ,
18
+ } ,
10
19
) => {
11
20
const data = ( isReactive ( tree ) ? tree : reactive ( tree ) ) as Reactive <
12
21
Record < string , unknown > [ ]
13
22
> ;
14
- const {
15
- branch : keyBranch ,
16
- children : keyChildren ,
17
- id : keyId ,
18
- index : keyIndex ,
19
- next : keyNext ,
20
- parent : keyParent ,
21
- prev : keyPrev ,
22
- siblings : keySiblings ,
23
- } = {
24
- branch : "branch" ,
25
- children : "children" ,
26
- id : "id" ,
27
- index : "index" ,
28
- next : "next" ,
29
- parent : "parent" ,
30
- prev : "prev" ,
31
- siblings : "siblings" ,
32
- ...options ,
33
- } ;
34
23
{
35
- const index = {
36
- get ( this : Record < string , unknown > ) {
37
- return ( this [ keySiblings ] as Record < string , unknown > [ ] ) . findIndex (
38
- ( { id } ) => this [ keyId ] === id ,
39
- ) ;
24
+ const properties = {
25
+ [ keyBranch ] : {
26
+ get ( this : Record < string , unknown > ) {
27
+ const ret = [ this ] ;
28
+ while ( ret [ 0 ] [ keyParent ] )
29
+ ret . unshift ( ret [ 0 ] [ keyParent ] as Record < string , unknown > ) ;
30
+ return ret ;
31
+ } ,
40
32
} ,
41
- } ;
42
- const prev = {
43
- get ( this : Record < string , unknown > ) {
44
- return ( this [ keySiblings ] as Record < string , unknown > [ ] ) [
45
- ( this [ keyIndex ] as number ) - 1
46
- ] ;
33
+ [ keyIndex ] : {
34
+ get ( this : Record < string , unknown > ) {
35
+ return ( this [ keySiblings ] as Record < string , unknown > [ ] ) . findIndex (
36
+ ( { id } ) => this [ keyId ] === id ,
37
+ ) ;
38
+ } ,
47
39
} ,
48
- } ;
49
- const next = {
50
- get ( this : Record < string , unknown > ) {
51
- return ( this [ keySiblings ] as Record < string , unknown > [ ] ) [
52
- ( this [ keyIndex ] as number ) + 1
53
- ] ;
40
+ [ keyNext ] : {
41
+ get ( this : Record < string , unknown > ) {
42
+ return ( this [ keySiblings ] as Record < string , unknown > [ ] ) [
43
+ ( this [ keyIndex ] as number ) + 1
44
+ ] ;
45
+ } ,
54
46
} ,
55
- } ;
56
- const branch = {
57
- get ( this : Record < string , unknown > ) {
58
- const ret = [ this ] ;
59
- while ( ret [ 0 ] [ keyParent ] )
60
- ret . unshift ( ret [ 0 ] [ keyParent ] as Record < string , unknown > ) ;
61
- return ret ;
47
+ [ keyPrev ] : {
48
+ get ( this : Record < string , unknown > ) {
49
+ return ( this [ keySiblings ] as Record < string , unknown > [ ] ) [
50
+ ( this [ keyIndex ] as number ) - 1
51
+ ] ;
52
+ } ,
62
53
} ,
63
54
} ;
64
55
const defineProperties = (
@@ -68,12 +59,11 @@ export default (
68
59
} ,
69
60
) => {
70
61
siblings . value . forEach ( ( value ) => {
71
- Reflect . defineProperty ( value , keyBranch , branch ) ;
72
- Reflect . defineProperty ( value , keyIndex , index ) ;
73
- Reflect . defineProperty ( value , keyNext , next ) ;
74
- Reflect . defineProperty ( value , keyParent , parent ) ;
75
- Reflect . defineProperty ( value , keyPrev , prev ) ;
76
- Reflect . defineProperty ( value , keySiblings , siblings ) ;
62
+ Object . defineProperties ( value , {
63
+ ...properties ,
64
+ [ keyParent ] : parent ,
65
+ [ keySiblings ] : siblings ,
66
+ } ) ;
77
67
defineProperties (
78
68
{
79
69
configurable,
0 commit comments