Skip to content

Commit

Permalink
fix(InputMenu/SelectMenu): use isEqual from ohash
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamincanac committed Nov 8, 2024
1 parent e831813 commit f943f88
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 30 deletions.
3 changes: 2 additions & 1 deletion src/runtime/components/InputMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,13 @@ extendDevtoolsMeta({ defaultProps: { items: ['Option 1', 'Option 2', 'Option 3']
import { computed, ref, toRef, onMounted } from 'vue'
import { ComboboxRoot, ComboboxArrow, ComboboxAnchor, ComboboxInput, ComboboxTrigger, ComboboxPortal, ComboboxContent, ComboboxViewport, ComboboxEmpty, ComboboxGroup, ComboboxLabel, ComboboxSeparator, ComboboxItem, ComboboxItemIndicator, TagsInputRoot, TagsInputItem, TagsInputItemText, TagsInputItemDelete, TagsInputInput, useForwardPropsEmits } from 'radix-vue'
import { defu } from 'defu'
import { isEqual } from 'ohash'
import { reactivePick } from '@vueuse/core'
import { useAppConfig } from '#imports'
import { useButtonGroup } from '../composables/useButtonGroup'
import { useComponentIcons } from '../composables/useComponentIcons'
import { useFormField } from '../composables/useFormField'
import { get, isEqual, escapeRegExp } from '../utils'
import { get, escapeRegExp } from '../utils'
import UIcon from './Icon.vue'
import UAvatar from './Avatar.vue'
import UChip from './Chip.vue'
Expand Down
3 changes: 2 additions & 1 deletion src/runtime/components/SelectMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,13 @@ extendDevtoolsMeta({ defaultProps: { items: ['Option 1', 'Option 2', 'Option 3']
import { computed, toRef } from 'vue'
import { ComboboxRoot, ComboboxArrow, ComboboxAnchor, ComboboxInput, ComboboxTrigger, ComboboxPortal, ComboboxContent, ComboboxViewport, ComboboxEmpty, ComboboxGroup, ComboboxLabel, ComboboxSeparator, ComboboxItem, ComboboxItemIndicator, useForwardPropsEmits } from 'radix-vue'
import { defu } from 'defu'
import { isEqual } from 'ohash'
import { reactivePick } from '@vueuse/core'
import { useAppConfig } from '#imports'
import { useButtonGroup } from '../composables/useButtonGroup'
import { useComponentIcons } from '../composables/useComponentIcons'
import { useFormField } from '../composables/useFormField'
import { get, isEqual, escapeRegExp } from '../utils'
import { get, escapeRegExp } from '../utils'
import UIcon from './Icon.vue'
import UAvatar from './Avatar.vue'
import UChip from './Chip.vue'
Expand Down
28 changes: 0 additions & 28 deletions src/runtime/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,34 +55,6 @@ export function set(object: Record<string, any>, path: (string | number)[] | str
}, object)
}

export function isEqual(a: any, b: any): boolean {
// Handle primitive types and referential equality
if (a === b) return true

// Handle null/undefined cases
if (a == null || b == null) return a === b

// Handle different types
if (typeof a !== typeof b) return false

// Handle arrays
if (Array.isArray(a) && Array.isArray(b)) {
if (a.length !== b.length) return false
return a.every((item, index) => isEqual(item, b[index]))
}

// Handle objects
if (typeof a === 'object') {
const keysA = Object.keys(a)
const keysB = Object.keys(b)

if (keysA.length !== keysB.length) return false
return keysA.every(key => key in b && isEqual(a[key], b[key]))
}

return false
}

export function looseToNumber(val: any): any {
const n = Number.parseFloat(val)
return Number.isNaN(n) ? val : n
Expand Down

0 comments on commit f943f88

Please sign in to comment.