mirror of
https://github.com/Doodle3D/Doodle3D-Core.git
synced 2024-12-22 19:13:49 +01:00
add some utils
This commit is contained in:
parent
831160394c
commit
81b144b86d
@ -1,3 +1,5 @@
|
|||||||
|
import PouchDB from 'pouchdb';
|
||||||
|
|
||||||
export function getLegalDBName(input) {
|
export function getLegalDBName(input) {
|
||||||
return encodeURIComponent(input.toLowerCase())
|
return encodeURIComponent(input.toLowerCase())
|
||||||
.replace(/\./g, '%2E')
|
.replace(/\./g, '%2E')
|
||||||
@ -11,3 +13,9 @@ export function getLegalDBName(input) {
|
|||||||
.toLowerCase()
|
.toLowerCase()
|
||||||
.replace(/(%..)/g, esc => `(${esc.substr(1)})`);
|
.replace(/(%..)/g, esc => `(${esc.substr(1)})`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const dbs = {};
|
||||||
|
export function getDb(dbUrl) {
|
||||||
|
if (!dbs[dbUrl]) dbs[dbUrl] = new PouchDB(dbUrl);
|
||||||
|
return dbs[dbUrl];
|
||||||
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { SubmissionError } from 'redux-form';
|
import { SubmissionError, startAsyncValidation, stopAsyncValidation } from 'redux-form';
|
||||||
|
|
||||||
// redux form submit promise wrapper
|
// redux form submit promise wrapper
|
||||||
// - turns all errors into SubmissionError
|
// - turns all errors into SubmissionError
|
||||||
@ -38,3 +38,12 @@ export function classNames(...names) {
|
|||||||
.filter(name => typeof name === 'string')
|
.filter(name => typeof name === 'string')
|
||||||
.join(' ');
|
.join(' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function asyncValidateForm(dispatch, form, asyncValidate, formData) {
|
||||||
|
dispatch(startAsyncValidation(form));
|
||||||
|
asyncValidate(formData).then(() => {
|
||||||
|
dispatch(stopAsyncValidation(form));
|
||||||
|
}).catch(error => {
|
||||||
|
dispatch(stopAsyncValidation(form, error));
|
||||||
|
})
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user