Created
May 3, 2016 10:19
-
-
Save uguisu-an/91068ae0fd4fdd2cda09708e30f05b4f to your computer and use it in GitHub Desktop.
Reactでバリデーションする。とりあえずthis.state.errorsをStore使って管理するのがいいのかなぁ。
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
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