Skip to content

Instantly share code, notes, and snippets.

View iagodahlem's full-sized avatar

Iago Dahlem Lorensini iagodahlem

View GitHub Profile

Trainee - CSS-in-JS

Desafio

O desafio da semana será implementar os componentes de Checkout do MUI usados no desafio da semana passada, utilizando styled-components.

Task 1: Setup do Styled Components e Tema

Considerando o desafio da semana passada.

@iagodahlem
iagodahlem / actionTypes.js
Created March 29, 2019 15:31
Scalable Frontend - The State Layer - Ducks Pattern
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',
@iagodahlem
iagodahlem / scalable-front-end-the-state-layer-dont-depend-on-the-return-of-actions-right-way.js
Last active March 29, 2019 15:17
Scalable Frontend - The State Layer - Don't depend on the return of actions (right way)
// action
const loadProduct = (id) => (dispatch, _, container) => {
container.loadProduct(id, {
onSuccess: (product, comments) => dispatch(loadProductSuccess(product, comments)),
onError: (error) => dispatch(loadProductError(error)),
})
}
// component
@iagodahlem
iagodahlem / scalable-front-end-the-state-layer-dont-depend-on-the-return-of-actions-wrong-way.js
Last active March 29, 2019 15:16
Scalable Frontend - The State Layer - Don't depend on the return of actions (wrong way)
// action
const loadProduct = (id) => (dispatch, _, container) => {
container.loadProduct({
onSuccess: (product) => dispatch(loadProductSuccess(product)),
onError: (error) => dispatch(loadProductError(error)),
})
}
// component
@iagodahlem
iagodahlem / scalable-front-end-the-state-layer-articles-reducer.js
Last active May 16, 2019 18:40
Scalable Frontend - The State Layer - Article Reducer
const articlesReducer = (state = initialState, action) => {
switch (action.type) {
case 'RECEIVE_DATA':
const articles = replaceRelationById(action.data, 'author')
return {
...state,
byId: byId(articles),
allIds: allIds(articles),
}
@iagodahlem
iagodahlem / scalable-front-end-the-state-layer-normalization-functions.js
Last active May 16, 2019 18:41
Scalable Frontend - The State Layer - Normalization Functions
const replaceRelationById = (entities, relation, idKey = 'id') => entities.map(item => ({
...item,
[relation]: item[relation][idKey],
}))
const extractRelation = (entities, relation) => entities.map(entity => entity[relation])
const byId = (entities, idKey = 'id') => entities
.reduce((obj, entity) => ({
...obj,
@iagodahlem
iagodahlem / scalable-front-end-the-state-layer-normalized-state-shape-organization.js
Last active May 16, 2019 18:37
Scalable Frontend - The State Layer - Normalized State Shape Organization
{
currentUser: {},
entities: {
articles: {},
authors: {},
},
ui: {},
}
@iagodahlem
iagodahlem / scalable-front-end-the-state-layer-normalized-state-shape.js
Last active March 29, 2019 15:08
Scalable Frontend - The State Layer - Normalized State Shape
{
articles: {
byId: {
'1': {
id: '1',
title: 'Managing all state in one reducer',
author: '1',
},
'2': {
id: '2',
@iagodahlem
iagodahlem / scalable-front-end-the-state-layer-articles-combine-reducers.js
Last active March 29, 2019 15:06
Scalable Frontend - The State Layer - Articles Combine Reducers
const isLoadingReducer = (state, action) => newState
const errorReducer = (state, action) => newState
const listReducer = (state, action) => newState
const articlesReducer = combineReducers({
isLoading: isLoadingReducer,
error: errorReducer,
list: listReducer,
@iagodahlem
iagodahlem / scalable-front-end-the-state-layer-articles-state-shape.js
Last active March 29, 2019 15:05
Scalable Frontend - The State Layer - Articles State Shape
{
isLoading: false,
error: null,
list: [] // <- this is the array of articles itself
}