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
import { AUTH } from './actionTypes';
export const reducer = (state, action) => {
switch(action.type) {
// ...
case AUTH.SIGN_IN_SUCCESS:
return {
...state,
user: action.user
};
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'
@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>
)
const createUser = (userData) => ({
type: 'CREATE_USER',
userData
});
{
type: 'CREATE_USER',
userData: { name: 'Aragorn', birthday: '03/01/2931' }
}
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')
};
class User {
constructor({ name, age }) {
this.name = name;
this.age = age;
}
validate() {
const hasName = Boolean(this.name);
const hasMinAge = this.age >= User.MIN_AGE;
// User.js
export default class User {
static LEGAL_AGE = 21;
constructor({ id, age }) {
this.id = id;
this.age = age;
}
// User.js
const LEGAL_AGE = 21;
export const isMajor = (user) => {
return user.age >= LEGAL_AGE;
};
// usage
import * as User from './User.js';
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) {