@@ -14,25 +14,8 @@ export default (
14
14
parent : keyParent = "parent" ,
15
15
prev : keyPrev = "prev" ,
16
16
siblings : keySiblings = "siblings" ,
17
- } : {
18
- branch ?: string ;
19
- children ?: string ;
20
- id ?: string ;
21
- index ?: string ;
22
- next ?: string ;
23
- parent ?: string ;
24
- prev ?: string ;
25
- siblings ?: string ;
26
17
} = { } ,
27
- ) : {
28
- add : ( pId : string ) => null | string ;
29
- down : ( pId : string ) => void ;
30
- leaves : ComputedRef < Record < string , unknown > [ ] > ;
31
- left : ( pId : string ) => null | string ;
32
- remove : ( pId : string ) => null | string ;
33
- right : ( pId : string ) => null | string ;
34
- up : ( pId : string ) => void ;
35
- } => {
18
+ ) => {
36
19
/* -------------------------------------------------------------------------- */
37
20
/* Constants */
38
21
/* -------------------------------------------------------------------------- */
@@ -61,20 +44,16 @@ export default (
61
44
} ,
62
45
[ keyNext ] : {
63
46
get ( this : Record < string , unknown > ) {
64
- return (
65
- ( this [ keySiblings ] as Record < string , unknown > [ ] ) [
66
- ( this [ keyIndex ] as number ) + 1
67
- ] ?? null
68
- ) ;
47
+ return ( this [ keySiblings ] as Record < string , unknown > [ ] ) [
48
+ ( this [ keyIndex ] as number ) + 1
49
+ ] ;
69
50
} ,
70
51
} ,
71
52
[ keyPrev ] : {
72
53
get ( this : Record < string , unknown > ) {
73
- return (
74
- ( this [ keySiblings ] as Record < string , unknown > [ ] ) [
75
- ( this [ keyIndex ] as number ) - 1
76
- ] ?? null
77
- ) ;
54
+ return ( this [ keySiblings ] as Record < string , unknown > [ ] ) [
55
+ ( this [ keyIndex ] as number ) - 1
56
+ ] ;
78
57
} ,
79
58
} ,
80
59
} ;
@@ -87,8 +66,8 @@ export default (
87
66
siblings : { configurable ?: boolean ; value : Record < string , unknown > [ ] } ,
88
67
parent : {
89
68
configurable ?: boolean ;
90
- value : null | Record < string , unknown > ;
91
- } = { value : null } ,
69
+ value ?: Record < string , unknown > | undefined ;
70
+ } = { } ,
92
71
) : Record < string , unknown > [ ] =>
93
72
siblings . value . flatMap ( ( value ) => {
94
73
Object . defineProperties ( value , {
@@ -132,13 +111,14 @@ export default (
132
111
/* Functions */
133
112
/* -------------------------------------------------------------------------- */
134
113
135
- const add = ( pId : string ) : null | string => {
136
- const the : null | Record < string , unknown > =
137
- leaves . value . find ( ( leaf ) => leaf [ keyId ] === pId ) ?? null ;
114
+ const add = ( pId : string ) : string | undefined => {
115
+ const the : Record < string , unknown > | undefined = leaves . value . find (
116
+ ( leaf ) => leaf [ keyId ] === pId ,
117
+ ) ;
138
118
if ( the ) {
139
- const children = ( the [ keyChildren ] ?? null ) as
140
- | null
141
- | Record < string , unknown > [ ] ;
119
+ const children = the [ keyChildren ] as
120
+ | Record < string , unknown > [ ]
121
+ | undefined ;
142
122
const index = the [ keyIndex ] as number ;
143
123
const siblings = the [ keySiblings ] as Record < string , unknown > [ ] ;
144
124
const id = v4 ( ) ;
@@ -155,14 +135,15 @@ export default (
155
135
}
156
136
return id ;
157
137
}
158
- return null ;
138
+ return undefined ;
159
139
} ;
160
140
161
141
/* -------------------------------------------------------------------------- */
162
142
163
143
const down = ( pId : string ) : void => {
164
- const the : null | Record < string , unknown > =
165
- leaves . value . find ( ( leaf ) => leaf [ keyId ] === pId ) ?? null ;
144
+ const the : Record < string , unknown > | undefined = leaves . value . find (
145
+ ( leaf ) => leaf [ keyId ] === pId ,
146
+ ) ;
166
147
if ( the ) {
167
148
const index : number = the [ keyIndex ] as number ;
168
149
const nextIndex : number = index + 1 ;
@@ -180,11 +161,12 @@ export default (
180
161
181
162
/* -------------------------------------------------------------------------- */
182
163
183
- const left = ( pId : string ) : null | string => {
184
- const the : null | Record < string , unknown > =
185
- leaves . value . find ( ( leaf ) => leaf [ keyId ] === pId ) ?? null ;
164
+ const left = ( pId : string ) : string | undefined => {
165
+ const the : Record < string , unknown > | undefined = leaves . value . find (
166
+ ( leaf ) => leaf [ keyId ] === pId ,
167
+ ) ;
186
168
if ( the ) {
187
- const parent = ( the [ keyParent ] ?? null ) as null | Record < string , unknown > ;
169
+ const parent = the [ keyParent ] as Record < string , unknown > | undefined ;
188
170
if ( parent ) {
189
171
const siblings = parent [ keySiblings ] as Record < string , unknown > [ ] ;
190
172
if ( parent [ keyParent ] ) {
@@ -199,18 +181,19 @@ export default (
199
181
}
200
182
}
201
183
}
202
- return null ;
184
+ return undefined ;
203
185
} ;
204
186
205
187
/* -------------------------------------------------------------------------- */
206
188
207
- const remove = ( pId : string ) : null | string => {
208
- const the : null | Record < string , unknown > =
209
- leaves . value . find ( ( leaf ) => leaf [ keyId ] === pId ) ?? null ;
189
+ const remove = ( pId : string ) : string | undefined => {
190
+ const the : Record < string , unknown > | undefined = leaves . value . find (
191
+ ( leaf ) => leaf [ keyId ] === pId ,
192
+ ) ;
210
193
if ( the ) {
211
- const next = ( the [ keyNext ] ?? null ) as null | Record < string , unknown > ;
212
- const parent = ( the [ keyParent ] ?? null ) as null | Record < string , unknown > ;
213
- const prev = ( the [ keyPrev ] ?? null ) as null | Record < string , unknown > ;
194
+ const next = the [ keyNext ] as Record < string , unknown > | undefined ;
195
+ const parent = the [ keyParent ] as Record < string , unknown > | undefined ;
196
+ const prev = the [ keyPrev ] as Record < string , unknown > | undefined ;
214
197
if ( parent ) {
215
198
let id : string ;
216
199
switch ( true ) {
@@ -231,16 +214,17 @@ export default (
231
214
return id ;
232
215
}
233
216
}
234
- return null ;
217
+ return undefined ;
235
218
} ;
236
219
237
220
/* -------------------------------------------------------------------------- */
238
221
239
- const right = ( pId : string ) : null | string => {
240
- const the : null | Record < string , unknown > =
241
- leaves . value . find ( ( leaf ) => leaf [ keyId ] === pId ) ?? null ;
222
+ const right = ( pId : string ) : string | undefined => {
223
+ const the : Record < string , unknown > | undefined = leaves . value . find (
224
+ ( leaf ) => leaf [ keyId ] === pId ,
225
+ ) ;
242
226
if ( the ) {
243
- const prev = ( the [ keyPrev ] ?? null ) as null | Record < string , unknown > ;
227
+ const prev = the [ keyPrev ] as Record < string , unknown > | undefined ;
244
228
if ( prev ) {
245
229
const children = ( prev [ keyChildren ] ?? [ ] ) as Record < string , unknown > [ ] ;
246
230
const id = prev [ keyId ] as string ;
@@ -254,14 +238,15 @@ export default (
254
238
return id ;
255
239
}
256
240
}
257
- return null ;
241
+ return undefined ;
258
242
} ;
259
243
260
244
/* -------------------------------------------------------------------------- */
261
245
262
246
const up = ( pId : string ) : void => {
263
- const the : null | Record < string , unknown > =
264
- leaves . value . find ( ( leaf ) => leaf [ keyId ] === pId ) ?? null ;
247
+ const the : Record < string , unknown > | undefined = leaves . value . find (
248
+ ( leaf ) => leaf [ keyId ] === pId ,
249
+ ) ;
265
250
if ( the ) {
266
251
const index : number = the [ keyIndex ] as number ;
267
252
const prevIndex : number = index - 1 ;
0 commit comments