fix(form): effect return map share same instance (#263)

This commit is contained in:
Yiwei Mao 2025-05-23 13:50:01 +08:00 committed by GitHub
parent dd727c8d63
commit 102980a23b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -44,29 +44,31 @@ import { renderForm } from './form-render';
import { FormPlugin } from './form-plugin'; import { FormPlugin } from './form-plugin';
const DEFAULT = { const DEFAULT = {
EFFECT_MAP: {}, // Different formModel should have different reference
EFFECT_RETURN_MAP: new Map([ EFFECT_MAP: () => ({}),
[DataEvent.onValueInitOrChange, {}], EFFECT_RETURN_MAP: () =>
[DataEvent.onValueChange, {}], new Map([
[DataEvent.onValueInit, {}], [DataEvent.onValueInitOrChange, {}],
[DataEvent.onArrayAppend, {}], [DataEvent.onValueChange, {}],
[DataEvent.onArrayDelete, {}], [DataEvent.onValueInit, {}],
]), [DataEvent.onArrayAppend, {}],
FORM_FEEDBACKS: [], [DataEvent.onArrayDelete, {}],
]),
FORM_FEEDBACKS: () => [],
VALID: null, VALID: null,
}; };
export class FormModelV2 extends FormModel implements Disposable { export class FormModelV2 extends FormModel implements Disposable {
protected effectMap: Record<string, EffectOptions[]> = DEFAULT.EFFECT_MAP; protected effectMap: Record<string, EffectOptions[]> = DEFAULT.EFFECT_MAP();
protected effectReturnMap: Map<DataEvent, Record<string, EffectReturn>> = protected effectReturnMap: Map<DataEvent, Record<string, EffectReturn>> =
DEFAULT.EFFECT_RETURN_MAP; DEFAULT.EFFECT_RETURN_MAP();
protected plugins: FormPlugin[] = []; protected plugins: FormPlugin[] = [];
protected node: FlowNodeEntity; protected node: FlowNodeEntity;
protected formFeedbacks: FormValidateReturn | undefined = DEFAULT.FORM_FEEDBACKS; protected formFeedbacks: FormValidateReturn | undefined = DEFAULT.FORM_FEEDBACKS();
protected onInitializedEmitter = new Emitter<FormModel>(); protected onInitializedEmitter = new Emitter<FormModel>();
@ -522,8 +524,8 @@ export class FormModelV2 extends FormModel implements Disposable {
}); });
}); });
this.effectMap = DEFAULT.EFFECT_MAP; this.effectMap = DEFAULT.EFFECT_MAP();
this.effectReturnMap = DEFAULT.EFFECT_RETURN_MAP; this.effectReturnMap = DEFAULT.EFFECT_RETURN_MAP();
this.plugins.forEach((p) => { this.plugins.forEach((p) => {
p.dispose(); p.dispose();
@ -531,7 +533,7 @@ export class FormModelV2 extends FormModel implements Disposable {
this.plugins = []; this.plugins = [];
this.formFeedbacks = DEFAULT.FORM_FEEDBACKS; this.formFeedbacks = DEFAULT.FORM_FEEDBACKS();
this._valid = DEFAULT.VALID; this._valid = DEFAULT.VALID;
this._formControl = undefined; this._formControl = undefined;