This file contains hidden or 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
{ | |
type: 'CREATE_USER', | |
userData: { name: 'Aragorn', birthday: '03/01/2931' } | |
} |
This file contains hidden or 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
const createUser = (userData) => ({ | |
type: 'CREATE_USER', | |
userData | |
}); |
This file contains hidden or 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
/* view/todo/TodoList.js */ | |
const TodoList = ({ todos, filter }) => ( | |
<ul> | |
{ | |
todos | |
.filter((todo) => todo.state === filter) | |
.map((todo) => | |
<li key={todo.id}>{ todo.text }</li> | |
) |
This file contains hidden or 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
export const AUTH = { | |
SIGN_IN_REQUEST: 'SIGN_IN_REQUEST', | |
SIGN_IN_SUCCESS: 'SIGN_IN_SUCCESS', | |
SIGN_IN_ERROR: 'SIGN_IN_ERROR' | |
}; | |
export const ARTICLE = { | |
LOAD_ARTICLE_REQUEST: 'LOAD_ARTICLE_REQUEST', | |
LOAD_ARTICLE_SUCCESS: 'LOAD_ARTICLE_SUCCESS', | |
LOAD_ARTICLE_ERROR: 'LOAD_ARTICLE_ERROR' |
This file contains hidden or 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 { AUTH } from './actionTypes'; | |
export const reducer = (state, action) => { | |
switch(action.type) { | |
// ... | |
case AUTH.SIGN_IN_SUCCESS: | |
return { | |
...state, | |
user: action.user | |
}; |
This file contains hidden or 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 { AUTH } from './actionTypes'; | |
export const reducer = (state, action) => { | |
switch(action.type) { | |
// ... | |
case AUTH.SIGN_IN_SUCCESS: | |
case AUTH.SIGN_IN_ERROR: | |
return { | |
...state, | |
showSpinner: false |
This file contains hidden or 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
{ | |
(isTouched || isSubmited) && !isValid && <ErrorMessage errors={errors} /> | |
} | |
{ | |
isValid && isSubmited && !errors && <Spinner /> | |
} |
This file contains hidden or 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
{ | |
(currentState === States.INVALID) && <ErrorMessage errors={errors} /> | |
} | |
{ | |
(currentState === States.SUBMITTING) && <Spinner /> | |
} |
This file contains hidden or 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 Auth from '../domain/auth'; | |
import { AUTH } from './actionTypes'; | |
const States = { | |
PRISTINE: 'PRISTINE', | |
VALID: 'VALID', | |
INVALID: 'INVALID', | |
SUBMITTING: 'SUBMITTING', | |
SUCCESS: 'SUCCESS' | |
}; |
This file contains hidden or 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
const loadProductsAction = () => (dispatch, _, container) => { | |
dispatch(showSpinner()); | |
container.loadProducts({ | |
onSuccess: (products) => { | |
dispatch(receiveProducts(products)); | |
dispatch(hideSpinner()); | |
}, | |
onError: (error) => { | |
dispatch(loadProductsError(error)); |