Skip to content
This repository has been archived by the owner on Oct 6, 2020. It is now read-only.

Commit

Permalink
Merge branch 'master' into v5
Browse files Browse the repository at this point in the history
  • Loading branch information
kylealwyn committed Aug 30, 2019
2 parents 2760d89 + ba29de2 commit 1a2884a
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 37 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ lib
.docz
.vscode/
coverage
.yalc
yalc.lock
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

<a name="4.1.7"></a>
## [4.1.7](https://github.com/sappira-inc/molekule/compare/v4.1.6...v4.1.7) (2019-08-21)


### Bug Fixes

* **FormBot:** Remove validation chaining for async validations ([#65](https://github.com/sappira-inc/molekule/issues/65)) ([fff8c25](https://github.com/sappira-inc/molekule/commit/fff8c25))



<a name="4.1.6"></a>
## [4.1.6](https://github.com/heydoctor/molekule/compare/v4.1.5...v4.1.6) (2019-08-15)

Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ $ npm install
$ npm run docs
```

### Previewing

We use [Yalc](https://github.com/whitecolor/yalc) to preview changes made to Molekule in consuming applications.

1. Install Yalc: `yarn global add yalc`.
1. Run `yarn preview` to publish the changes to your local `~/.yalc` directory, and re-publish when changes are detected.
1. Run `yarn link molekule` or `yalc add molekule` in the consuming application. Both will replace the consuming application's node module with the yalc version, the latter will also update the consuming application's `package.json`.
1. Start (or restart) the consuming application to preview the changes locally (including on subsequent changes).
1. Once you're satisfied with your changes, run: `yalc remove molekule` in the consuming application to remove the yalc version, and `yarn install --check-files` to restore the package.

## Releasing

```
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

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

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "molekule",
"description": "React component library built on top of styled-components and styled-system",
"version": "4.1.6",
"version": "4.1.7",
"main": "lib/molekule.js",
"module": "lib/molekule.es.js",
"files": [
Expand All @@ -22,6 +22,7 @@
"docs:build": "rimraf dist && docz build",
"docs:deploy": "npm run docs:build && gh-pages -d dist",
"prepublishOnly": "npm-run-all build",
"preview": "nodemon -w src -x 'yalc publish --push --changed'",
"rollup": "rollup -c",
"test": "jest",
"lint": "eslint src",
Expand Down Expand Up @@ -63,6 +64,7 @@
"jest": "^24.1.0",
"jest-dom": "^3.1.3",
"jest-styled-components": "^6.3.1",
"nodemon": "^1.19.1",
"npm-run-all": "^4.1.5",
"react": "^16.8.3",
"react-dom": "^16.8.3",
Expand Down
65 changes: 30 additions & 35 deletions src/Form/Formbot.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,44 +143,39 @@ export default class Formbot extends React.Component {
}

const fieldValue = this.state.values[field];
let errorMsg;

if (hasSchema && typeof validation.validate === 'function') {
validation
.validate(fieldValue, validationOpts)
.catch(e => {
errorMsg = e.message;
})
.finally(() => {
this.updateField(field, { validated: true }).then(() => {
this.setErrors({ [field]: errorMsg }, resolve);
});
});

return;
}

try {
if (typeof validation === 'function') {
validation(fieldValue);
} else {
Object.keys(validation).forEach(method => {
const validator = VALIDATIONS[method];

if (!validator) {
throw new Error(`Formbot: "${method}" is not a built-in validator.`);
}

validator(fieldValue, validation[method]);
});
}
} catch (err) {
errorMsg = err.message;
} finally {
const setFieldValidated = message => {
this.updateField(field, { validated: true }).then(() => {
this.setErrors({ [field]: errorMsg }, resolve);
this.setErrors({ [field]: message }, resolve);
});
};

Promise.resolve()
.then(() => {
if (hasSchema && typeof validation.validate === 'function') {
return validation.validate(fieldValue, validationOpts);
} else if (typeof validation === 'function') {
validation(fieldValue);
} else {
Object.keys(validation).forEach(method => {
const validator = VALIDATIONS[method];

if (!validator) {
throw new Error(`Formbot: "${method}" is not a built-in validator.`);
}

validator(fieldValue, validation[method]);
});
}

return true;
})
.then(() => {
setFieldValidated();
})
.catch(err => {
setFieldValidated(err.message);
});
}
});
}

Expand Down

0 comments on commit 1a2884a

Please sign in to comment.