-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* master: (32 commits) fixed npm script problem and upgraded redux-form added form support with redux-form npm knows how to prefix binaries oops, left in debugger call improved syntax for including styles fixed erikras/react-redux-universal-hot-example#77 added apology for #60 in the README linted url-loader fix for images switched back to file-loader to avoid error from requireServerImage() fixes #39 Works on mac now Added better-npm-run to allow setting env-vars on all platforms fixed cat pic on server render minor grammar and js style tweak to README added url-loader to production webpack, too merged PR #67. lint-corrected merge. added obligatory cat pic. changed to use url-loader to encode small images. made pass lint incorporated PR #67 and added some comments to promise chaining in createTransitionHook() work on forms work on forms ...
- Loading branch information
Showing
23 changed files
with
372 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
webpack/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ node_modules/ | |
dist/ | ||
*.iml | ||
webpack-stats.json | ||
npm-debug.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
import {createFormReducer} from 'redux-form'; | ||
import surveyValidation from '../validation/surveyValidation'; | ||
export info from './info'; | ||
export widgets from './widgets'; | ||
export auth from './auth'; | ||
export counter from './counter'; | ||
export const survey = createFormReducer('survey', ['name', 'email', 'occupation'], surveyValidation); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,39 @@ | ||
import path from 'path'; | ||
const readStats = () => { | ||
// don't cache the `webpack-stats.json` on dev so we read the file on each request. | ||
// on production, use simple `require` to cache the file | ||
const stats = require('../webpack-stats.json'); | ||
if (__DEVELOPMENT__) { | ||
delete require.cache[require.resolve('../webpack-stats.json')]; | ||
} | ||
return stats; | ||
}; | ||
|
||
const pathToSrc = path.resolve(__dirname, '.'); | ||
export function requireServerCss(cssPath) { | ||
if (__CLIENT__) { | ||
throw new Error('image-resolver called on browser'); | ||
} | ||
return readStats().css.modules[cssPath.slice(__dirname.length)]; | ||
} | ||
|
||
export function requireServerImage(imagePath) { | ||
if (!imagePath) { | ||
return ''; | ||
} | ||
if (__CLIENT__) { | ||
throw new Error('server-side only resolver called on client'); | ||
} | ||
const images = readStats().images; | ||
if (!images) { | ||
return ''; | ||
} | ||
|
||
// Find the correct image | ||
const regex = new RegExp(`${imagePath}$`); | ||
const image = images.find(img => regex.test(img.original)); | ||
|
||
// Serve image. | ||
if (image) return image.compiled; | ||
|
||
export function relativeToSrc(value) { | ||
return value.slice(pathToSrc.length); | ||
// Serve a not-found asset maybe? | ||
return ''; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import {createValidator, required, maxLength, email} from './validation'; | ||
|
||
const surveyValidation = createValidator({ | ||
name: [required, maxLength(10)], | ||
email: [required, email], | ||
occupation: maxLength(20) // single rules don't have to in an array | ||
}); | ||
export default surveyValidation; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const isEmpty = value => value === undefined || value === null || value === ''; | ||
const join = (rules) => value => rules.map(rule => rule(value)).filter(error => !!error)[0 /* first error */]; | ||
|
||
export function email(value) { | ||
// Let's not start a debate on email regex. This is just for an example app! | ||
if (!isEmpty(value) && !/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i.test(value)) { | ||
return 'Invalid email address'; | ||
} | ||
} | ||
|
||
export function required(value) { | ||
if (isEmpty(value)) { | ||
return 'Required'; | ||
} | ||
} | ||
|
||
export function minLength(min) { | ||
return value => { | ||
if (!isEmpty(value) && value.length < min) { | ||
return `Must be fewer than ${min} characters`; | ||
} | ||
} | ||
} | ||
|
||
export function maxLength(max) { | ||
return value => { | ||
if (!isEmpty(value) && value.length > max) { | ||
return `Must be fewer than ${max} characters`; | ||
} | ||
} | ||
} | ||
|
||
export function createValidator(rules) { | ||
return (data = {}) => { | ||
const errors = {}; | ||
Object.keys(rules).forEach((key) => { | ||
const rule = join([].concat(rules[key])); // concat enables both functions and arrays of functions | ||
const error = rule(data[key]); | ||
if (error) { | ||
errors[key] = error; | ||
} | ||
}); | ||
return errors; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.