Skip to content

Commit

Permalink
fix(Form): fix Form not update sometimes
Browse files Browse the repository at this point in the history
  • Loading branch information
qiqiboy committed Jul 24, 2019
1 parent b965116 commit 5aeec23
Show file tree
Hide file tree
Showing 12 changed files with 103 additions and 19 deletions.
27 changes: 24 additions & 3 deletions dist/react-formutil.cjs.development.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/react-formutil.cjs.development.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/react-formutil.cjs.production.js

Large diffs are not rendered by default.

27 changes: 24 additions & 3 deletions dist/react-formutil.esm.development.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/react-formutil.esm.development.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/react-formutil.esm.production.js

Large diffs are not rendered by default.

27 changes: 24 additions & 3 deletions dist/react-formutil.umd.development.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/react-formutil.umd.development.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/react-formutil.umd.production.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-formutil",
"version": "0.6.6",
"version": "0.6.7",
"description": "Happy to build the forms in React ^_^",
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js",
Expand Down
6 changes: 3 additions & 3 deletions src/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,10 @@ class Form extends Component {
const $parsedTree = this.$$deepParseObject($stateTree);

utils.objectEach(this.$$registers, (handler, name) => {
const data = name in $stateTree ? $stateTree[name] : utils.parsePath($parsedTree, name);
let pathData;

if (!utils.isUndefined(data) || force) {
const $newState = processer(data, handler);
if (force || (pathData = utils.pathExist($parsedTree, name))) {
const $newState = processer(pathData && pathData.data, handler);

if ($newState) {
const $prevValue = this.$formutil.$weakParams[name];
Expand Down
21 changes: 21 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,27 @@ export function parsePath(...args) {
}
}

export function pathExist(scope, path) {
const pathWords = path
.split(PATH_REGEXP)
.map(s => s.trim())
.filter(item => item !== '');

for (let index = 0, len = pathWords.length; index < len; index++) {
const word = executeWord(pathWords[index]);

if (word in scope) {
if (index + 1 === len) {
return {
data: scope[word]
};
}

scope = scope[word];
}
}
}

export function createRef(ref, value) {
if (ref) {
if (isFunction(ref)) {
Expand Down

0 comments on commit 5aeec23

Please sign in to comment.