Skip to content

Commit

Permalink
refactor: remove redundant pick function
Browse files Browse the repository at this point in the history
  • Loading branch information
KaelWD committed Feb 19, 2025
1 parent 4df71de commit a438986
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 25 deletions.
4 changes: 2 additions & 2 deletions packages/vuetify/src/components/VInput/VInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { makeValidationProps, useValidation } from '@/composables/validation'

// Utilities
import { computed } from 'vue'
import { EventProp, genericComponent, getUid, only, propsFactory, useRender } from '@/util'
import { EventProp, genericComponent, getUid, pick, propsFactory, useRender } from '@/util'

// Types
import type { ComputedRef, PropType, Ref } from 'vue'
Expand Down Expand Up @@ -64,7 +64,7 @@ export const makeVInputProps = propsFactory({

...makeComponentProps(),
...makeDensityProps(),
...only(makeDimensionProps(), [
...pick(makeDimensionProps(), [
'maxWidth',
'minWidth',
'width',
Expand Down
4 changes: 2 additions & 2 deletions packages/vuetify/src/components/VOtpInput/VOtpInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { useProxiedModel } from '@/composables/proxiedModel'

// Utilities
import { computed, nextTick, ref, watch } from 'vue'
import { filterInputAttrs, focusChild, genericComponent, only, propsFactory, useRender } from '@/util'
import { filterInputAttrs, focusChild, genericComponent, pick, propsFactory, useRender } from '@/util'

// Types
import type { PropType } from 'vue'
Expand Down Expand Up @@ -50,7 +50,7 @@ export const makeVOtpInputProps = propsFactory({

...makeDimensionProps(),
...makeFocusProps(),
...only(makeVFieldProps({
...pick(makeVFieldProps({
variant: 'outlined' as const,
}), [
'baseColor',
Expand Down
4 changes: 2 additions & 2 deletions packages/vuetify/src/components/VStepper/VStepper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { IconValue } from '@/composables/icons'

// Utilities
import { computed, toRefs } from 'vue'
import { genericComponent, getPropertyFromItem, only, propsFactory, useRender } from '@/util'
import { genericComponent, getPropertyFromItem, pick, propsFactory, useRender } from '@/util'

// Types
import type { PropType } from 'vue'
Expand Down Expand Up @@ -79,7 +79,7 @@ export const makeVStepperProps = propsFactory({
selectedClass: 'v-stepper-item--selected',
}),
...makeVSheetProps(),
...only(makeVStepperActionsProps(), ['prevText', 'nextText']),
...pick(makeVStepperActionsProps(), ['prevText', 'nextText']),
}, 'VStepper')

export const VStepper = genericComponent<VStepperSlots>()({
Expand Down
4 changes: 2 additions & 2 deletions packages/vuetify/src/components/VTimeline/VTimeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { makeThemeProps, provideTheme } from '@/composables/theme'

// Utilities
import { computed, toRef } from 'vue'
import { convertToUnit, genericComponent, only, propsFactory, useRender } from '@/util'
import { convertToUnit, genericComponent, pick, propsFactory, useRender } from '@/util'

// Types
import type { Prop } from 'vue'
Expand Down Expand Up @@ -52,7 +52,7 @@ export const makeVTimelineProps = propsFactory({
validator: (v: any) => ['start', 'end', 'both'].includes(v),
} as Prop<TimelineTruncateLine>,

...only(makeVTimelineItemProps({
...pick(makeVTimelineItemProps({
lineInset: 0,
}), ['dotColor', 'fillDot', 'hideOpposite', 'iconColor', 'lineInset', 'size']),
...makeComponentProps(),
Expand Down
4 changes: 2 additions & 2 deletions packages/vuetify/src/labs/VFileUpload/VFileUpload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { useProxiedModel } from '@/composables/proxiedModel'

// Utilities
import { onMounted, onUnmounted, ref, shallowRef } from 'vue'
import { filterInputAttrs, genericComponent, only, propsFactory, useRender, wrapInArray } from '@/util'
import { filterInputAttrs, genericComponent, pick, propsFactory, useRender, wrapInArray } from '@/util'

// Types
import type { PropType, VNode } from 'vue'
Expand Down Expand Up @@ -79,7 +79,7 @@ export const makeVFileUploadProps = propsFactory({

...makeDelayProps(),
...makeDensityProps(),
...only(makeVDividerProps({
...pick(makeVDividerProps({
length: 150,
}), ['length', 'thickness', 'opacity']),
...makeVSheetProps(),
Expand Down
18 changes: 3 additions & 15 deletions packages/vuetify/src/util/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,9 @@ export function pick<
> (obj: T, paths: U[]): MaybePick<T, U> {
const found: any = {}

const keys = new Set(Object.keys(obj))
for (const path of paths) {
if (keys.has(path)) {
found[path] = obj[path]
for (const key of paths) {
if (Object.hasOwn(obj, key)) {
found[key] = obj[key]
}
}

Expand Down Expand Up @@ -273,17 +272,6 @@ export function omit<
return clone
}

export function only<
T extends object,
U extends Extract<keyof T, string>
> (obj: T, include: U[]): Pick<T, U> {
const clone = {} as T

include.forEach(prop => clone[prop] = obj[prop])

return clone
}

const onRE = /^on[^a-z]/
export const isOn = (key: string) => onRE.test(key)

Expand Down

0 comments on commit a438986

Please sign in to comment.