Skip to content

Commit

Permalink
fix: fix simplify nullable value
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Mar 3, 2023
1 parent 88a3b86 commit 0aa5f36
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ Schema.prototype.pattern = function pattern(regexp) {

Schema.prototype.simplify = function simplify(this: Schema, value) {
if (deepEqual(value, this.meta.default)) return null
if (isNullable(value)) return value
if (this.type === 'object' || this.type === 'dict') {
const result: Dict = {}
for (const key in value) {
Expand Down Expand Up @@ -228,7 +229,7 @@ Schema.prototype.simplify = function simplify(this: Schema, value) {
}

Schema.prototype.toString = function toString(this: Schema, inline?: boolean) {
return formatters[this.type]?.(this, inline) ?? (console.log(this), `Schema<${this.type}>`)
return formatters[this.type]?.(this, inline) ?? `Schema<${this.type}>`
}

Schema.prototype.role = function role(role, extra) {
Expand Down Expand Up @@ -449,7 +450,7 @@ Schema.extend('union', (data, { list, toString }) => {
Schema.extend('intersect', (data, { list, toString }, strict) => {
let result
for (const inner of list!) {
const value = Schema.resolve(data, inner, true)[0]
const value: any = Schema.resolve(data, inner, true)[0]
if (isNullable(value)) continue
if (isNullable(result)) {
result = value
Expand Down
4 changes: 2 additions & 2 deletions packages/form/src/schema.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<el-dropdown-item command="delete">删除分支</el-dropdown-item>
</template>
<span>当满足条件:</span>
<k-filter-button v-model="config.$switch.branches[index].case" :disabled="disabled"></k-filter-button>
<k-filter-button v-model="config.$switch.branches[index].case" :options="schema.meta.extra" :disabled="disabled"></k-filter-button>
</k-schema>
<k-schema
v-model="config.$switch.default"
Expand Down Expand Up @@ -335,7 +335,7 @@ watch(() => props.modelValue, (value) => {
watch(config, (value) => {
if (!props.schema) return
if (props.initial === undefined && deepEqual(value, props.schema.meta.default)) {
if (deepEqual(value, props.schema.meta.default)) {
emit('update:modelValue', undefined)
} else {
emit('update:modelValue', value)
Expand Down

0 comments on commit 0aa5f36

Please sign in to comment.