Skip to content

Commit

Permalink
Formatted with better prettier settings
Browse files Browse the repository at this point in the history
  • Loading branch information
erikras committed May 9, 2017
1 parent dc80420 commit 496b21d
Show file tree
Hide file tree
Showing 203 changed files with 5,868 additions and 7,564 deletions.
36 changes: 19 additions & 17 deletions examples/asyncValidation/devServer.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
var path = require('path');
var express = require('express');
var webpack = require('webpack');
var config = require('./webpack.config.dev');
var path = require('path')
var express = require('express')
var webpack = require('webpack')
var config = require('./webpack.config.dev')

var app = express();
var compiler = webpack(config);
var app = express()
var compiler = webpack(config)

app.use(require('webpack-dev-middleware')(compiler, {
noInfo: true,
publicPath: config.output.publicPath
}));
app.use(
require('webpack-dev-middleware')(compiler, {
noInfo: true,
publicPath: config.output.publicPath,
})
)

app.use(require('webpack-hot-middleware')(compiler));
app.use(require('webpack-hot-middleware')(compiler))

app.get('*', function(req, res) {
res.sendFile(path.join(__dirname, 'index.html'));
});
res.sendFile(path.join(__dirname, 'index.html'))
})

app.listen(3030, 'localhost', function(err) {
if (err) {
console.log(err);
return;
console.log(err)
return
}

console.log('Listening at http://localhost:3030');
});
console.log('Listening at http://localhost:3030')
})
35 changes: 26 additions & 9 deletions examples/asyncValidation/src/AsyncValidationForm.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,44 @@
import React from 'react'
import { Field, reduxForm } from 'redux-form'
import {Field, reduxForm} from 'redux-form'
import validate from './validate'
import asyncValidate from './asyncValidate'

const renderField = ({ input, label, type, meta: { asyncValidating, touched, error } }) => (
const renderField = ({
input,
label,
type,
meta: {asyncValidating, touched, error},
}) => (
<div>
<label>{label}</label>
<div className={asyncValidating ? 'async-validating' : ''}>
<input {...input} type={type} placeholder={label}/>
<input {...input} type={type} placeholder={label} />
{touched && error && <span>{error}</span>}
</div>
</div>
)

const AsyncValidationForm = (props) => {
const { handleSubmit, pristine, reset, submitting } = props
const AsyncValidationForm = props => {
const {handleSubmit, pristine, reset, submitting} = props
return (
<form onSubmit={handleSubmit}>
<Field name="username" type="text" component={renderField} label="Username"/>
<Field name="password" type="password" component={renderField} label="Password"/>
<Field
name="username"
type="text"
component={renderField}
label="Username"
/>
<Field
name="password"
type="password"
component={renderField}
label="Password"
/>
<div>
<button type="submit" disabled={submitting}>Sign Up</button>
<button type="button" disabled={pristine || submitting} onClick={reset}>Clear Values</button>
<button type="button" disabled={pristine || submitting} onClick={reset}>
Clear Values
</button>
</div>
</form>
)
Expand All @@ -31,5 +48,5 @@ export default reduxForm({
form: 'asyncValidation', // a unique identifier for this form
validate,
asyncValidate,
asyncBlurFields: [ 'username' ]
asyncBlurFields: ['username'],
})(AsyncValidationForm)
15 changes: 7 additions & 8 deletions examples/asyncValidation/src/asyncValidate.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms))

const asyncValidate = (values/*, dispatch */) => {
return sleep(1000) // simulate server latency
.then(() => {
if ([ 'john', 'paul', 'george', 'ringo' ].includes(values.username)) {
throw { username: 'That username is taken' }
}
})
const asyncValidate = (values /*, dispatch */) => {
return sleep(1000).then(() => {
// simulate server latency
if (['john', 'paul', 'george', 'ringo'].includes(values.username)) {
throw {username: 'That username is taken'}
}
})
}

export default asyncValidate

64 changes: 38 additions & 26 deletions examples/asyncValidation/src/index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
import React from 'react'
import ReactDOM from 'react-dom'
import { Provider } from 'react-redux'
import { createStore, combineReducers } from 'redux'
import { reducer as reduxFormReducer } from 'redux-form'
import { App, Code, Markdown, Values, generateExampleBreadcrumbs } from 'redux-form-website-template'
import {Provider} from 'react-redux'
import {createStore, combineReducers} from 'redux'
import {reducer as reduxFormReducer} from 'redux-form'
import {
App,
Code,
Markdown,
Values,
generateExampleBreadcrumbs,
} from 'redux-form-website-template'

const dest = document.getElementById('content')
const reducer = combineReducers({
form: reduxFormReducer // mounted under "form"
form: reduxFormReducer, // mounted under "form"
})
const store =
(window.devToolsExtension ? window.devToolsExtension()(createStore) : createStore)(reducer)
const store = (window.devToolsExtension
? window.devToolsExtension()(createStore)
: createStore)(reducer)

const showResults = values =>
new Promise(resolve => {
setTimeout(() => { // simulate server latency
setTimeout(() => {
// simulate server latency
window.alert(`You submitted:\n\n${JSON.stringify(values, null, 2)}`)
resolve()
}, 500)
Expand All @@ -35,37 +43,44 @@ let render = () => {
*/
version="6.6.3"
path="/examples/asyncValidation"
breadcrumbs={generateExampleBreadcrumbs('asyncValidation', 'Async Validation Example', '6.6.3')}>

<Markdown content={readme}/>

<div style={{ textAlign: 'center' }}>
<a href="https://codesandbox.io/s/nKlYo387"
breadcrumbs={generateExampleBreadcrumbs(
'asyncValidation',
'Async Validation Example',
'6.6.3'
)}
>

<Markdown content={readme} />

<div style={{textAlign: 'center'}}>
<a
href="https://codesandbox.io/s/nKlYo387"
target="_blank"
style={{ fontSize: '1.5em' }}>
<i className="fa fa-codepen"/> Open in Sandbox
style={{fontSize: '1.5em'}}
>
<i className="fa fa-codepen" /> Open in Sandbox
</a>
</div>

<h2>Form</h2>

<AsyncValidationForm onSubmit={showResults}/>
<AsyncValidationForm onSubmit={showResults} />

<Values form="asyncValidation"/>
<Values form="asyncValidation" />

<h2>Code</h2>

<h4>validate.js</h4>

<Code source={rawValidate}/>
<Code source={rawValidate} />

<h4>asyncValidate.js</h4>

<Code source={rawAsyncValidate}/>
<Code source={rawAsyncValidate} />

<h4>AsyncValidationForm.js</h4>

<Code source={raw}/>
<Code source={raw} />

</App>
</Provider>,
Expand All @@ -77,12 +92,9 @@ if (module.hot) {
// Support hot reloading of components
// and display an overlay for runtime errors
const renderApp = render
const renderError = (error) => {
const renderError = error => {
const RedBox = require('redbox-react')
ReactDOM.render(
<RedBox error={error} className="redbox"/>,
dest
)
ReactDOM.render(<RedBox error={error} className="redbox" />, dest)
}
render = () => {
try {
Expand Down
8 changes: 4 additions & 4 deletions examples/asyncValidation/src/reducer.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { combineReducers } from 'redux'
import { reducer as formReducer } from 'redux-form'
import {combineReducers} from 'redux'
import {reducer as formReducer} from 'redux-form'
import validate from './validate'

const reducer = combineReducers({
form: formReducer.validation({
asyncValidation: validate // "asyncValidation" is the form name given to reduxForm() decorator
})
asyncValidation: validate, // "asyncValidation" is the form name given to reduxForm() decorator
}),
})

export default reducer
1 change: 0 additions & 1 deletion examples/asyncValidation/src/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ const validate = values => {
}

export default validate

36 changes: 19 additions & 17 deletions examples/fieldArrays/devServer.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
var path = require('path');
var express = require('express');
var webpack = require('webpack');
var config = require('./webpack.config.dev');
var path = require('path')
var express = require('express')
var webpack = require('webpack')
var config = require('./webpack.config.dev')

var app = express();
var compiler = webpack(config);
var app = express()
var compiler = webpack(config)

app.use(require('webpack-dev-middleware')(compiler, {
noInfo: true,
publicPath: config.output.publicPath
}));
app.use(
require('webpack-dev-middleware')(compiler, {
noInfo: true,
publicPath: config.output.publicPath,
})
)

app.use(require('webpack-hot-middleware')(compiler));
app.use(require('webpack-hot-middleware')(compiler))

app.get('*', function(req, res) {
res.sendFile(path.join(__dirname, 'index.html'));
});
res.sendFile(path.join(__dirname, 'index.html'))
})

app.listen(3030, 'localhost', function(err) {
if (err) {
console.log(err);
return;
console.log(err)
return
}

console.log('Listening at http://localhost:3030');
});
console.log('Listening at http://localhost:3030')
})
Loading

0 comments on commit 496b21d

Please sign in to comment.