mirror of
https://github.com/Doodle3D/Doodle3D-Core.git
synced 2024-12-22 11:03:48 +01:00
add react utils
This commit is contained in:
parent
9f03127cc7
commit
831160394c
40
package-lock.json
generated
40
package-lock.json
generated
@ -1084,6 +1084,11 @@
|
|||||||
"ms": "2.0.0"
|
"ms": "2.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"deep-equal": {
|
||||||
|
"version": "1.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/deep-equal/-/deep-equal-1.0.1.tgz",
|
||||||
|
"integrity": "sha1-9dJgKStmDghO/0zbyfCK0yR0SLU="
|
||||||
|
},
|
||||||
"detect-indent": {
|
"detect-indent": {
|
||||||
"version": "4.0.0",
|
"version": "4.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/detect-indent/-/detect-indent-4.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/detect-indent/-/detect-indent-4.0.0.tgz",
|
||||||
@ -1120,6 +1125,11 @@
|
|||||||
"es6-symbol": "3.1.1"
|
"es6-symbol": "3.1.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"es6-error": {
|
||||||
|
"version": "4.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/es6-error/-/es6-error-4.0.2.tgz",
|
||||||
|
"integrity": "sha1-7sXHJurO9Rt/a3PCDbbhsTsGnJg="
|
||||||
|
},
|
||||||
"es6-iterator": {
|
"es6-iterator": {
|
||||||
"version": "2.0.3",
|
"version": "2.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/es6-iterator/-/es6-iterator-2.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/es6-iterator/-/es6-iterator-2.0.3.tgz",
|
||||||
@ -2412,6 +2422,11 @@
|
|||||||
"ansi-regex": "2.1.1"
|
"ansi-regex": "2.1.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"hoist-non-react-statics": {
|
||||||
|
"version": "2.3.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/hoist-non-react-statics/-/hoist-non-react-statics-2.3.1.tgz",
|
||||||
|
"integrity": "sha1-ND24TGAYxlB3iJgkATWhQg7iLOA="
|
||||||
|
},
|
||||||
"home-or-tmp": {
|
"home-or-tmp": {
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/home-or-tmp/-/home-or-tmp-2.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/home-or-tmp/-/home-or-tmp-2.0.0.tgz",
|
||||||
@ -2552,6 +2567,11 @@
|
|||||||
"dev": true,
|
"dev": true,
|
||||||
"optional": true
|
"optional": true
|
||||||
},
|
},
|
||||||
|
"is-promise": {
|
||||||
|
"version": "2.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/is-promise/-/is-promise-2.1.0.tgz",
|
||||||
|
"integrity": "sha1-eaKp7OfwlugPNtKy87wWwf9L8/o="
|
||||||
|
},
|
||||||
"is-stream": {
|
"is-stream": {
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz",
|
||||||
@ -2666,6 +2686,11 @@
|
|||||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.4.tgz",
|
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.4.tgz",
|
||||||
"integrity": "sha1-eCA6TRwyiuHYbcpkYONptX9AVa4="
|
"integrity": "sha1-eCA6TRwyiuHYbcpkYONptX9AVa4="
|
||||||
},
|
},
|
||||||
|
"lodash-es": {
|
||||||
|
"version": "4.17.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/lodash-es/-/lodash-es-4.17.4.tgz",
|
||||||
|
"integrity": "sha1-3MHXVS4VCgZABzupyzHXDwMpUOc="
|
||||||
|
},
|
||||||
"loose-envify": {
|
"loose-envify": {
|
||||||
"version": "1.3.1",
|
"version": "1.3.1",
|
||||||
"resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.3.1.tgz",
|
"resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.3.1.tgz",
|
||||||
@ -3023,6 +3048,21 @@
|
|||||||
"set-immediate-shim": "1.0.1"
|
"set-immediate-shim": "1.0.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"redux-form": {
|
||||||
|
"version": "7.1.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/redux-form/-/redux-form-7.1.2.tgz",
|
||||||
|
"integrity": "sha512-NQdYtHx0Tx2oRQs7c3+aiJxoVAwIyn3lmm2sf2vQ/eSRE1xLWdygoCWPLHk0FYT31FJY3Ec1d/5Vtkd0/GVQBg==",
|
||||||
|
"requires": {
|
||||||
|
"deep-equal": "1.0.1",
|
||||||
|
"es6-error": "4.0.2",
|
||||||
|
"hoist-non-react-statics": "2.3.1",
|
||||||
|
"invariant": "2.2.2",
|
||||||
|
"is-promise": "2.1.0",
|
||||||
|
"lodash": "4.17.4",
|
||||||
|
"lodash-es": "4.17.4",
|
||||||
|
"prop-types": "15.6.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"regenerate": {
|
"regenerate": {
|
||||||
"version": "1.3.3",
|
"version": "1.3.3",
|
||||||
"resolved": "https://registry.npmjs.org/regenerate/-/regenerate-1.3.3.tgz",
|
"resolved": "https://registry.npmjs.org/regenerate/-/regenerate-1.3.3.tgz",
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
"proptypes": "^1.1.0",
|
"proptypes": "^1.1.0",
|
||||||
"raw-loader": "^0.5.1",
|
"raw-loader": "^0.5.1",
|
||||||
"react": "^16.0.0",
|
"react": "^16.0.0",
|
||||||
|
"redux-form": "^7.1.2",
|
||||||
"regenerator-runtime": "^0.11.0",
|
"regenerator-runtime": "^0.11.0",
|
||||||
"semver": "^5.4.1",
|
"semver": "^5.4.1",
|
||||||
"shortid": "^2.2.8",
|
"shortid": "^2.2.8",
|
||||||
|
@ -6,5 +6,6 @@ import * as exportUtils from './exportUtils.js';
|
|||||||
import * as webGLSupport from './webGLSupport.js';
|
import * as webGLSupport from './webGLSupport.js';
|
||||||
import * as vectorUtils from './vectorUtils.js';
|
import * as vectorUtils from './vectorUtils.js';
|
||||||
import * as textUtils from './textUtils.js';
|
import * as textUtils from './textUtils.js';
|
||||||
|
import * as reactUtils from './reactUtils.js';
|
||||||
|
|
||||||
export { dbUtils, asyncUtils, imageUtils, exportUtils, webGLSupport, binaryUtils, vectorUtils, textUt };
|
export { dbUtils, asyncUtils, imageUtils, exportUtils, webGLSupport, binaryUtils, vectorUtils, textUtils, reactUtils };
|
||||||
|
40
src/utils/reactUtils.js
Normal file
40
src/utils/reactUtils.js
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
import { SubmissionError } from 'redux-form';
|
||||||
|
|
||||||
|
// redux form submit promise wrapper
|
||||||
|
// - turns all errors into SubmissionError
|
||||||
|
// - fills _error field, enables showing main error message in form
|
||||||
|
// - includes superlogin's validationErrors
|
||||||
|
export function formPromiseWrapper(promise) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
promise
|
||||||
|
.then(resolve)
|
||||||
|
.catch(error => {
|
||||||
|
// axius (used by superlogin http utils) puts response data in response.data
|
||||||
|
if (error.response && error.response.data) {
|
||||||
|
error = error.response.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
// promise middleware puts actual error in reason
|
||||||
|
if (error.action && error.reason) {
|
||||||
|
error = error.reason;
|
||||||
|
}
|
||||||
|
const submissionErrors = {
|
||||||
|
_error: error.message || error.error
|
||||||
|
};
|
||||||
|
// add superlogin validation errors
|
||||||
|
// joined because superlogin creates arrays per field
|
||||||
|
for (const prop in error.validationErrors) {
|
||||||
|
submissionErrors[prop] = error.validationErrors[prop].join(', ');
|
||||||
|
}
|
||||||
|
const submissionError = new SubmissionError(submissionErrors);
|
||||||
|
|
||||||
|
reject(submissionError);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function classNames(...names) {
|
||||||
|
return names
|
||||||
|
.filter(name => typeof name === 'string')
|
||||||
|
.join(' ');
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user