Skip to content

Commit

Permalink
fix(config): support function as default value
Browse files Browse the repository at this point in the history
fix #41
  • Loading branch information
qmhc committed Jun 16, 2022
1 parent 005ba93 commit f44047e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions common/config/src/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export function useProps<T>(
) as PropsConfig<T[keyof T]>
const validator = isFunction(propOptions.validator) ? propOptions.validator : null
const defaultValue = propOptions.default
const isFunc = propOptions.isFunc || false
const isFunc = !!propOptions.isFunc
const getDefault = () =>
(!isFunc && isFunction(defaultValue) ? defaultValue() : defaultValue) as T[keyof T]

Expand All @@ -66,7 +66,9 @@ export function useProps<T>(
props[key] = computed(() => {
if (isNull(sourceProps[key])) {
if (!isNull(configProps.value[key])) {
return configProps.value[key]!
const providedValue = configProps.value[key]!

return !isFunc && isFunction(providedValue) ? providedValue() : providedValue
}

return getDefault()
Expand Down

0 comments on commit f44047e

Please sign in to comment.