Skip to content

Instantly share code, notes, and snippets.

@uguisu-an
Created May 3, 2016 10:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uguisu-an/91068ae0fd4fdd2cda09708e30f05b4f to your computer and use it in GitHub Desktop.
Save uguisu-an/91068ae0fd4fdd2cda09708e30f05b4f to your computer and use it in GitHub Desktop.
Reactでバリデーションする。とりあえずthis.state.errorsをStore使って管理するのがいいのかなぁ。
import { MapStore } from 'flux/utils';
import Immutable from 'immutable';
import AppDispatcher from './AppDispatcher';
class ErrorStore extends MapStore {
getInitialState() {
return new Immutable.Map();
}
reduce(state, action) {
const { type, name, validationMessage } = action;
switch (type) {
case 'validate':
if (!validationMessage) {
return state.delete(name);
}
return state.set(name, validationMessage);
default:
return state;
}
}
}
export default new ErrorStore(AppDispatcher);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment