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
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
/* 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
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
{ | |
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
var path = require('path'); | |
module.exports = { | |
'config': path.resolve('config', 'database.json'), | |
'migrations-path': path.resolve('src/infra/sequelize', 'migrations'), | |
'models-path': path.resolve('src/infra/sequelize', 'models'), | |
'seeders-path': path.resolve('src/infra/sequelize', 'seeders') | |
}; |
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
class User { | |
constructor({ name, age }) { | |
this.name = name; | |
this.age = age; | |
} | |
validate() { | |
const hasName = Boolean(this.name); | |
const hasMinAge = this.age >= User.MIN_AGE; |
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
// User.js | |
export default class User { | |
static LEGAL_AGE = 21; | |
constructor({ id, age }) { | |
this.id = id; | |
this.age = age; | |
} | |
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
// User.js | |
const LEGAL_AGE = 21; | |
export const isMajor = (user) => { | |
return user.age >= LEGAL_AGE; | |
}; | |
// usage | |
import * as User from './User.js'; |
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 default ({ validateUser, userRepository }) => async (userData, { onSuccess, onError, onValidationError }) => { | |
if(!validateUser(userData)) { | |
return onValidationError(new Error('Invalid user')); | |
} | |
try { | |
const user = await userRepository.add(userData); | |
onSuccess(user); | |
} catch(error) { |