From 389905d7b2714e15743169622b728a94bd69a0ac Mon Sep 17 00:00:00 2001 From: Claudio Savino Date: Tue, 28 Mar 2023 12:56:58 +0200 Subject: [PATCH] fix: fix: empty constructor fix: empty constructor --- CHANGELOG.md | 4 ++++ src/Form.ts | 2 +- src/State.ts | 2 +- tests/data/_.fixes.ts | 3 +++ tests/data/forms/form.empty.constructor.ts | 4 ++++ tests/fixes.props.ts | 5 +++++ 6 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 tests/data/forms/form.empty.constructor.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f1a59b6..77fa4184 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 5.5.2 (next) + +- Fix: Empty Constructor (was requiring at least an empyt object if used with only class fileds definitions) + # 5.5.1 (next) - Introduced `preserveDeletedFieldsValues` form option (disabled by default). diff --git a/src/Form.ts b/src/Form.ts index 5d92f7e9..43e2c7c2 100755 --- a/src/Form.ts +++ b/src/Form.ts @@ -22,7 +22,7 @@ export default class Form extends Base implements FormInterface { debouncedValidation: any = null; constructor( - setup: FieldsDefinitions, + setup: FieldsDefinitions = {}, { name = "", options = {}, diff --git a/src/State.ts b/src/State.ts index 4dd89cc1..8394ed90 100755 --- a/src/State.ts +++ b/src/State.ts @@ -60,7 +60,7 @@ export default class State implements StateInterface { this.observeOptions(); } - initProps(initial: any) { + initProps(initial: any = {}) { const initialProps: any = _.pick(initial, [ ...props.separated, ...props.validation, diff --git a/tests/data/_.fixes.ts b/tests/data/_.fixes.ts index f31ba43e..b6827072 100755 --- a/tests/data/_.fixes.ts +++ b/tests/data/_.fixes.ts @@ -1,6 +1,8 @@ /** FIXES */ +import $formEmptyConstructor from "./forms/form.empty.constructor"; + import $A from "./forms/fixes/form.a"; import $B from "./forms/fixes/form.b"; import $C from "./forms/fixes/form.c"; @@ -42,6 +44,7 @@ import $585 from "./forms/fixes/form.585"; import $531 from "./forms/fixes/form.531"; export default { + $formEmptyConstructor, $A, $B, $C, diff --git a/tests/data/forms/form.empty.constructor.ts b/tests/data/forms/form.empty.constructor.ts new file mode 100644 index 00000000..4c8b1758 --- /dev/null +++ b/tests/data/forms/form.empty.constructor.ts @@ -0,0 +1,4 @@ +import MobxReactForm from "../../../src"; + +// EMPTY CONSTRUCTOR +export default new MobxReactForm(); // do not change! \ No newline at end of file diff --git a/tests/fixes.props.ts b/tests/fixes.props.ts index d2c7d9c2..dc040478 100755 --- a/tests/fixes.props.ts +++ b/tests/fixes.props.ts @@ -2,6 +2,11 @@ import { expect } from 'chai'; import $ from './data/_.fixes'; // FORMS +describe('Check Fixes $E props check', () => { + it('$formEmptyConstrcutor size should be equal 0', () => + expect($.$formEmptyConstructor.size).to.be.equal(0)); +}); + describe('Check Fixes $E props check', () => { it('$E places extra should be array', () =>