Skip to content

Instantly share code, notes, and snippets.

View talyssonoc's full-sized avatar
💭
I want to live where soul meets body.

Talysson de Oliveira Cassiano talyssonoc

💭
I want to live where soul meets body.
View GitHub Profile
{
type: 'CREATE_USER',
userData: { name: 'Aragorn', birthday: '03/01/2931' }
}
const createUser = (userData) => ({
type: 'CREATE_USER',
userData
});
@talyssonoc
talyssonoc / 1 - before.js
Created January 18, 2019 13:03
Before and after using a Redux selector
/* view/todo/TodoList.js */
const TodoList = ({ todos, filter }) => (
<ul>
{
todos
.filter((todo) => todo.state === filter)
.map((todo) =>
<li key={todo.id}>{ todo.text }</li>
)
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'
import { AUTH } from './actionTypes';
export const reducer = (state, action) => {
switch(action.type) {
// ...
case AUTH.SIGN_IN_SUCCESS:
return {
...state,
user: action.user
};
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
{
(isTouched || isSubmited) && !isValid && <ErrorMessage errors={errors} />
}
{
isValid && isSubmited && !errors && <Spinner />
}
{
(currentState === States.INVALID) && <ErrorMessage errors={errors} />
}
{
(currentState === States.SUBMITTING) && <Spinner />
}
import Auth from '../domain/auth';
import { AUTH } from './actionTypes';
const States = {
PRISTINE: 'PRISTINE',
VALID: 'VALID',
INVALID: 'INVALID',
SUBMITTING: 'SUBMITTING',
SUCCESS: 'SUCCESS'
};
const loadProductsAction = () => (dispatch, _, container) => {
dispatch(showSpinner());
container.loadProducts({
onSuccess: (products) => {
dispatch(receiveProducts(products));
dispatch(hideSpinner());
},
onError: (error) => {
dispatch(loadProductsError(error));