Skip to content

Commit

Permalink
fix: fix duplicated field $state
Browse files Browse the repository at this point in the history
  • Loading branch information
qiqiboy committed Sep 4, 2023
1 parent 6b114c2 commit b45428f
Show file tree
Hide file tree
Showing 12 changed files with 23 additions and 42 deletions.
12 changes: 4 additions & 8 deletions dist/react-formutil.cjs.development.js
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,7 @@ var Form = /*#__PURE__*/function (_Component) {
warning__default['default']($curRegistered.$$reserved, "The Field with a name '".concat(name, "' has been registered!"));
$handler.$$reset($curRegistered.$getState());
hasDup = delete $$regDuplications[name];
_this.$$formShouldUpdateFields[name] = true;
});
if (hasDup) {
_this.$render();
Expand Down Expand Up @@ -1526,7 +1527,6 @@ function renderField($fieldutil, props) {
function createHandler($this, owner) {
var $fieldHandler = {
$$FIELD_UUID: $this.$$FIELD_UUID,
$name: $this.props.name,
$$reset: $$reset,
$$merge: $$merge,
$$detectChange: $$detectChange,
Expand Down Expand Up @@ -1909,8 +1909,7 @@ var Field = /*#__PURE__*/function (_Component) {
}
_this2.$registered = (_this2.$formContext.$$registers || {})[_this2.$fieldHandler.$name] || _this2.$fieldHandler;
if (shouldInitial) {
var initialState = _this2.$registered.$getState();
_this2.$fieldHandler.$$reset(initialState);
_this2.$fieldHandler.$$reset();
_this2.$fieldHandler.$validate();
}
return _this2._render();
Expand Down Expand Up @@ -2818,17 +2817,14 @@ function useField(name) {
var _useState = useState(function () {
$this.$$FIELD_UUID = GET_FIELD_UUID();
$this.$fieldHandler = $registered = createHandler($this);
$this.$fieldHandler.$$reset();
$this.$fieldHandler.$validate();
}),
_useState2 = _slicedToArray(_useState, 2),
setState = _useState2[1];
if (!$registered) {
$registered = ($formContext.$$registers || {})[$this.$fieldHandler.$name] || $this.$fieldHandler;
}
useState(function () {
var initialState = $registered.$getState();
$this.$fieldHandler.$$reset(initialState);
$this.$fieldHandler.$validate();
});
_useEffect(function () {
var $state = $this.$state;
if ($this.isMounting) {
Expand Down
2 changes: 1 addition & 1 deletion dist/react-formutil.cjs.production.js

Large diffs are not rendered by default.

12 changes: 4 additions & 8 deletions dist/react-formutil.esm.development.js
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,7 @@ var Form = /*#__PURE__*/function (_Component) {
warning($curRegistered.$$reserved, "The Field with a name '".concat(name, "' has been registered!"));
$handler.$$reset($curRegistered.$getState());
hasDup = delete $$regDuplications[name];
_this.$$formShouldUpdateFields[name] = true;
});
if (hasDup) {
_this.$render();
Expand Down Expand Up @@ -1365,7 +1366,6 @@ function renderField($fieldutil, props) {
function createHandler($this, owner) {
var $fieldHandler = {
$$FIELD_UUID: $this.$$FIELD_UUID,
$name: $this.props.name,
$$reset: $$reset,
$$merge: $$merge,
$$detectChange: $$detectChange,
Expand Down Expand Up @@ -1748,8 +1748,7 @@ var Field = /*#__PURE__*/function (_Component) {
}
_this2.$registered = (_this2.$formContext.$$registers || {})[_this2.$fieldHandler.$name] || _this2.$fieldHandler;
if (shouldInitial) {
var initialState = _this2.$registered.$getState();
_this2.$fieldHandler.$$reset(initialState);
_this2.$fieldHandler.$$reset();
_this2.$fieldHandler.$validate();
}
return _this2._render();
Expand Down Expand Up @@ -2657,17 +2656,14 @@ function useField(name) {
var _useState = useState(function () {
$this.$$FIELD_UUID = GET_FIELD_UUID();
$this.$fieldHandler = $registered = createHandler($this);
$this.$fieldHandler.$$reset();
$this.$fieldHandler.$validate();
}),
_useState2 = _slicedToArray(_useState, 2),
setState = _useState2[1];
if (!$registered) {
$registered = ($formContext.$$registers || {})[$this.$fieldHandler.$name] || $this.$fieldHandler;
}
useState(function () {
var initialState = $registered.$getState();
$this.$fieldHandler.$$reset(initialState);
$this.$fieldHandler.$validate();
});
_useEffect(function () {
var $state = $this.$state;
if ($this.isMounting) {
Expand Down
2 changes: 1 addition & 1 deletion dist/react-formutil.esm.production.js

Large diffs are not rendered by default.

12 changes: 4 additions & 8 deletions dist/react-formutil.umd.development.js
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,7 @@
warning_1($curRegistered.$$reserved, "The Field with a name '".concat(name, "' has been registered!"));
$handler.$$reset($curRegistered.$getState());
hasDup = delete $$regDuplications[name];
_this.$$formShouldUpdateFields[name] = true;
});
if (hasDup) {
_this.$render();
Expand Down Expand Up @@ -2267,7 +2268,6 @@
function createHandler($this, owner) {
var $fieldHandler = {
$$FIELD_UUID: $this.$$FIELD_UUID,
$name: $this.props.name,
$$reset: $$reset,
$$merge: $$merge,
$$detectChange: $$detectChange,
Expand Down Expand Up @@ -2650,8 +2650,7 @@
}
_this2.$registered = (_this2.$formContext.$$registers || {})[_this2.$fieldHandler.$name] || _this2.$fieldHandler;
if (shouldInitial) {
var initialState = _this2.$registered.$getState();
_this2.$fieldHandler.$$reset(initialState);
_this2.$fieldHandler.$$reset();
_this2.$fieldHandler.$validate();
}
return _this2._render();
Expand Down Expand Up @@ -3559,17 +3558,14 @@
var _useState = useState(function () {
$this.$$FIELD_UUID = GET_FIELD_UUID();
$this.$fieldHandler = $registered = createHandler($this);
$this.$fieldHandler.$$reset();
$this.$fieldHandler.$validate();
}),
_useState2 = _slicedToArray(_useState, 2),
setState = _useState2[1];
if (!$registered) {
$registered = ($formContext.$$registers || {})[$this.$fieldHandler.$name] || $this.$fieldHandler;
}
useState(function () {
var initialState = $registered.$getState();
$this.$fieldHandler.$$reset(initialState);
$this.$fieldHandler.$validate();
});
_useEffect(function () {
var $state = $this.$state;
if ($this.isMounting) {
Expand Down
2 changes: 1 addition & 1 deletion dist/react-formutil.umd.production.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-formutil",
"version": "1.1.7",
"version": "1.1.8",
"description": "Happy to build the forms in React ^_^",
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js",
Expand Down Expand Up @@ -116,7 +116,7 @@
"rollup-plugin-filesize": "9.0.2",
"rollup-plugin-sass": "1.2.2",
"rollup-plugin-terser": "7.0.2",
"typescript": "4.0.5"
"typescript": "5.2.2"
},
"dependencies": {
"hoist-non-react-statics": "^3.3.2",
Expand Down
4 changes: 1 addition & 3 deletions src/Field.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,7 @@ class Field extends Component {
(this.$formContext.$$registers || {})[this.$fieldHandler.$name] || this.$fieldHandler;

if (shouldInitial) {
const initialState = this.$registered.$getState();

this.$fieldHandler.$$reset(initialState);
this.$fieldHandler.$$reset();
this.$fieldHandler.$validate();
}

Expand Down
2 changes: 2 additions & 0 deletions src/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ class Form extends Component {
$handler.$$reset($curRegistered.$getState());

hasDup = delete $$regDuplications[name];

this.$$formShouldUpdateFields[name] = true;
});

if (hasDup) {
Expand Down
2 changes: 0 additions & 2 deletions src/fieldHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ export function createHandler($this, owner) {
const $fieldHandler = {
$$FIELD_UUID: $this.$$FIELD_UUID,

$name: $this.props.name,

$$reset,
$$merge,
$$detectChange,
Expand Down
10 changes: 3 additions & 7 deletions src/hooks/useField.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,15 @@ function useField(name, props = {}) {
const [, setState] = useState(() => {
$this.$$FIELD_UUID = GET_FIELD_UUID();
$this.$fieldHandler = $registered = createHandler($this);

$this.$fieldHandler.$$reset();
$this.$fieldHandler.$validate();
});

if (!$registered) {
$registered = ($formContext.$$registers || {})[$this.$fieldHandler.$name] || $this.$fieldHandler;
}

useState(() => {
const initialState = $registered.$getState();

$this.$fieldHandler.$$reset(initialState);
$this.$fieldHandler.$validate();
});

_useEffect(() => {
const { $state } = $this;

Expand Down
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"noImplicitThis": true,
"noImplicitAny": false,
"strictNullChecks": true,
"suppressImplicitAnyIndexErrors": true,
"noUnusedLocals": true,
"importHelpers": true
},
Expand Down

0 comments on commit b45428f

Please sign in to comment.