From fff8c2596f88a9356f5904837b4b9c95cb8e94b1 Mon Sep 17 00:00:00 2001 From: Scott Schlegel Date: Wed, 21 Aug 2019 12:55:34 -0700 Subject: [PATCH 1/3] fix(FormBot): Remove validation chaining for async validations (#65) * Remove validation chaining for async validations * Added resolved Promise to handle async validation * Fixed context issue --- src/Form/Formbot.js | 65 +++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 35 deletions(-) diff --git a/src/Form/Formbot.js b/src/Form/Formbot.js index 556f8df..36b2da2 100644 --- a/src/Form/Formbot.js +++ b/src/Form/Formbot.js @@ -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); }); - } }); } From 0e19223f931cfb0780c8dd16af51dd43aa238ce2 Mon Sep 17 00:00:00 2001 From: Kyle Alwyn Date: Wed, 21 Aug 2019 12:56:35 -0700 Subject: [PATCH 2/3] chore(release): 4.1.7 --- CHANGELOG.md | 10 ++++++++++ package-lock.json | 2 +- package.json | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 38d33bb..79b2ac1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. + +## [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)) + + + ## [4.1.6](https://github.com/heydoctor/molekule/compare/v4.1.5...v4.1.6) (2019-08-15) diff --git a/package-lock.json b/package-lock.json index 886931a..aeb78ff 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "molekule", - "version": "4.1.6", + "version": "4.1.7", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 0f5673d..308b2a5 100644 --- a/package.json +++ b/package.json @@ -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": [ From ba29de22176349a4eec454c7ccfaf0b9825287b0 Mon Sep 17 00:00:00 2001 From: Claire Hsu Date: Thu, 22 Aug 2019 09:31:51 -0700 Subject: [PATCH 3/3] chore: Add preview scripts and documentation (#55) --- .gitignore | 2 ++ README.md | 10 ++++++++++ package.json | 2 ++ 3 files changed, 14 insertions(+) diff --git a/.gitignore b/.gitignore index ada7cbf..25dd68a 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ lib .docz .vscode/ coverage +.yalc +yalc.lock diff --git a/README.md b/README.md index 89078a4..625c8d9 100644 --- a/README.md +++ b/README.md @@ -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 ``` diff --git a/package.json b/package.json index 308b2a5..a684669 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "docs:build": "rimraf dist && yarn 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", @@ -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",