Skip to content

Commit 0734fad

Browse files
committed
chore: refactor solution
1 parent 848deab commit 0734fad

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

packages/vuetify/src/composables/nested/nested.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {
2727
leafSelectStrategy,
2828
leafSingleSelectStrategy,
2929
} from './selectStrategies'
30-
import { consoleError, getCurrentInstance, getUid, propsFactory } from '@/util'
30+
import { arrayDiff, consoleError, getCurrentInstance, getUid, propsFactory } from '@/util'
3131

3232
// Types
3333
import type { InjectionKey, PropType, Ref } from 'vue'
@@ -303,13 +303,13 @@ export const useNested = (props: NestedProps) => {
303303
const newActivated = activeStrategy.value.activate({
304304
id,
305305
value,
306-
activated: activated.value,
306+
activated: new Set(activated.value),
307307
children: children.value,
308308
parents: parents.value,
309309
event,
310310
})
311311

312-
newActivated && newActivated.size && activated.value !== newActivated && (activated.value = newActivated)
312+
newActivated && arrayDiff(activated.value, newActivated).length && (activated.value = newActivated)
313313
},
314314
children,
315315
parents,

packages/vuetify/src/util/helpers.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -378,11 +378,14 @@ export function filterInputAttrs (attrs: Record<string, unknown>) {
378378

379379
/**
380380
* Returns the set difference of B and A, i.e. the set of elements in B but not in A
381+
* A and B can be sets, but the function always returns the result as an array.
381382
*/
382-
export function arrayDiff (a: any[], b: any[]): any[] {
383+
export function arrayDiff (a: any[] | Set<any>, b: any[] | Set<any>): any[] {
383384
const diff: any[] = []
384-
for (let i = 0; i < b.length; i++) {
385-
if (!a.includes(b[i])) diff.push(b[i])
385+
const aArr: any[] = a instanceof Set ? Array.from(a) : a
386+
const bArr: any[] = b instanceof Set ? Array.from(b) : b
387+
for (let i = 0; i < bArr.length; i++) {
388+
if (!aArr.includes(bArr[i])) diff.push(bArr[i])
386389
}
387390
return diff
388391
}

0 commit comments

Comments
 (0)