mirror of
https://github.com/Doodle3D/Doodle3D-Core.git
synced 2024-12-22 11:03:48 +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) {
|
||||
return encodeURIComponent(input.toLowerCase())
|
||||
.replace(/\./g, '%2E')
|
||||
@ -11,3 +13,9 @@ export function getLegalDBName(input) {
|
||||
.toLowerCase()
|
||||
.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
|
||||
// - turns all errors into SubmissionError
|
||||
@ -38,3 +38,12 @@ export function classNames(...names) {
|
||||
.filter(name => typeof name === 'string')
|
||||
.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