Skip to content

Commit

Permalink
refactor(core): controlled ==> designable
Browse files Browse the repository at this point in the history
  • Loading branch information
janryWang committed Jun 2, 2021
1 parent 3508ca2 commit ac79c19
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const SchemaRenderWidget: React.FC<ISchemaRenderWidgetProps> = observer(
const form = useMemo(
() =>
createForm({
controlled: true,
designable: true,
}),
[]
)
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/models/ArrayField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class ArrayField<
address: FormPathPattern,
props: IFieldProps<Decorator, Component>,
form: Form,
controlled: boolean
designable: boolean
) {
super(
address,
Expand All @@ -24,7 +24,7 @@ export class ArrayField<
value: isArr(props.value) ? props.value : [],
},
form,
controlled
designable
)
}

Expand Down
20 changes: 10 additions & 10 deletions packages/core/src/models/Field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,13 @@ export class Field<
address: FormPathPattern,
props: IFieldProps<Decorator, Component, TextType, ValueType>,
form: Form,
controlled: boolean
designable: boolean
) {
this.initialize(props, form)
this.makeIndexes(address)
this.makeObservable(controlled)
this.makeReactive(controlled)
this.onInit(controlled)
this.makeObservable(designable)
this.makeReactive(designable)
this.onInit(designable)
}

protected makeIndexes(address: FormPathPattern) {
Expand Down Expand Up @@ -151,8 +151,8 @@ export class Field<
this.component = toArr(this.props.component)
}

protected makeObservable(controlled: boolean) {
if (controlled) return
protected makeObservable(designable: boolean) {
if (designable) return
define(this, {
title: observable.ref,
description: observable.ref,
Expand Down Expand Up @@ -223,8 +223,8 @@ export class Field<
})
}

protected makeReactive(controlled: boolean) {
if (controlled) return
protected makeReactive(designable: boolean) {
if (designable) return
this.disposers.push(
reaction(
() => this.value,
Expand Down Expand Up @@ -663,10 +663,10 @@ export class Field<

getState: IModelGetter<IFieldState> = modelStateGetter(this)

onInit = (controlled: boolean) => {
onInit = (designable: boolean) => {
this.initialized = true
batch.scope(() => {
initFieldValue(this, controlled)
initFieldValue(this, designable)
})
batch.scope(() => {
initFieldUpdate(this)
Expand Down
18 changes: 9 additions & 9 deletions packages/core/src/models/Form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export class Form<ValueType extends object = any> {
}

protected makeReactive() {
if (this.props.controlled) return
if (this.props.designable) return
this.disposers.push(
observe(this.initialValues, (change) => {
if (change.type === 'add' || change.type === 'set') {
Expand Down Expand Up @@ -301,13 +301,13 @@ export class Form<ValueType extends object = any> {
const address = FormPath.parse(props.basePath).concat(props.name)
const identifier = address.toString()
if (!identifier) return
if (!this.fields[identifier] || this.props.controlled) {
if (!this.fields[identifier] || this.props.designable) {
batch(() => {
this.fields[identifier] = new Field(
address,
props,
this,
this.props.controlled
this.props.designable
)
})
this.notify(LifeCycleTypes.ON_FORM_GRAPH_CHANGE)
Expand All @@ -324,13 +324,13 @@ export class Form<ValueType extends object = any> {
const address = FormPath.parse(props.basePath).concat(props.name)
const identifier = address.toString()
if (!identifier) return
if (!this.fields[identifier] || this.props.controlled) {
if (!this.fields[identifier] || this.props.designable) {
batch(() => {
this.fields[identifier] = new ArrayField(
address,
props,
this,
this.props.controlled
this.props.designable
)
})
this.notify(LifeCycleTypes.ON_FORM_GRAPH_CHANGE)
Expand All @@ -347,13 +347,13 @@ export class Form<ValueType extends object = any> {
const address = FormPath.parse(props.basePath).concat(props.name)
const identifier = address.toString()
if (!identifier) return
if (!this.fields[identifier] || this.props.controlled) {
if (!this.fields[identifier] || this.props.designable) {
batch(() => {
this.fields[identifier] = new ObjectField(
address,
props,
this,
this.props.controlled
this.props.designable
)
})
this.notify(LifeCycleTypes.ON_FORM_GRAPH_CHANGE)
Expand All @@ -370,13 +370,13 @@ export class Form<ValueType extends object = any> {
const address = FormPath.parse(props.basePath).concat(props.name)
const identifier = address.toString()
if (!identifier) return
if (!this.fields[identifier] || this.props.controlled) {
if (!this.fields[identifier] || this.props.designable) {
batch(() => {
this.fields[identifier] = new VoidField(
address,
props,
this,
this.props.controlled
this.props.designable
)
})
this.notify(LifeCycleTypes.ON_FORM_GRAPH_CHANGE)
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/models/ObjectField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class ObjectField<
address: FormPathPattern,
props: IFieldProps<Decorator, Component>,
form: Form,
controlled: boolean
designable: boolean
) {
super(
address,
Expand All @@ -21,7 +21,7 @@ export class ObjectField<
value: isObj(props.value) ? props.value : {},
},
form,
controlled
designable
)
}

Expand Down
14 changes: 7 additions & 7 deletions packages/core/src/models/VoidField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ export class VoidField<Decorator = any, Component = any, TextType = any> {
address: FormPathPattern,
props: IVoidFieldProps<Decorator, Component>,
form: Form,
controlled: boolean
designable: boolean
) {
this.initialize(props, form)
this.makeIndexes(address)
this.makeObservable(controlled)
this.makeReactive(controlled)
this.makeObservable(designable)
this.makeReactive(designable)
this.onInit()
}

Expand Down Expand Up @@ -93,8 +93,8 @@ export class VoidField<Decorator = any, Component = any, TextType = any> {
this.component = toArr(this.props.component)
}

protected makeObservable(controlled: boolean) {
if (controlled) return
protected makeObservable(designable: boolean) {
if (designable) return
define(this, {
title: observable.ref,
description: observable.ref,
Expand Down Expand Up @@ -132,8 +132,8 @@ export class VoidField<Decorator = any, Component = any, TextType = any> {
})
}

protected makeReactive(controlled: boolean) {
if (controlled) return
protected makeReactive(designable: boolean) {
if (designable) return
this.form.addEffects(this, () => {
toArr(this.props.reactions).forEach((reaction) => {
if (isFn(reaction)) {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/shared/internals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ export const isEmptyWithField = (field: GeneralField, value: any) => {
return !isValid(value)
}

export const initFieldValue = (field: Field, controlled: boolean) => {
export const initFieldValue = (field: Field, designable: boolean) => {
GlobalState.initializing = true
if (isEmptyWithField(field, field.initialValue)) {
if (isValid(field.props.initialValue)) {
Expand All @@ -383,7 +383,7 @@ export const initFieldValue = (field: Field, controlled: boolean) => {
field.value = field.props.initialValue
}
}
if (controlled) {
if (designable) {
if (isValid(field.props.initialValue)) {
field.initialValue = field.props.initialValue
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ export interface IFormProps<T extends object = any> {
readPretty?: boolean
effects?: (form: Form<T>) => void
validateFirst?: boolean
controlled?: boolean
designable?: boolean
}

export type IFormMergeStrategy =
Expand Down

0 comments on commit ac79c19

Please sign in to comment.