Skip to content

Instantly share code, notes, and snippets.

View Tiagoperes's full-sized avatar

Tiago Peres França Tiagoperes

View GitHub Profile
import { createCacheManager } from '@zup-next/redux-action-cache'
import resources from './resources'
const { profile, wallet, catalog, order } = resources
const cacheManager = createCacheManager({
include: [profile.types.LOAD, wallet.types.LOAD, catalog.types.LOAD],
invalidations: [
{ type: 'pattern', invalidatedBy: /(.+)\/LOAD_ERROR$/, invalidated: '$1/LOAD' },
{ invalidatedBy: order.types.CREATE_SUCCESS, invalidated: wallet.types.LOAD },
include: [
{ type: 'pattern', name: /\/LOAD$/ }
]
import { createStore, applyMiddleware, combineReducers } from 'redux'
import createSagaMiddleware from 'redux-saga'
import resources from './resources'
import cacheManager from './cache'
import { createEffects, getTypeToSagaMap } from '@zup-next/redux-resource'
import { mapValues } from 'lodash'
const reducers = combineReducers(mapValues(resources, 'reducer'))
export const rootSaga = function* run() {
{
"_beagleType_":"text",
"value":"New text comming from BFF"
}
@Tiagoperes
Tiagoperes / beagle-schema.ts
Last active January 25, 2020 14:03
Schema for the Beagle test
/***
* This file is automatically generated by the BFF. Please, don't change it. To update it, run:
* yarn update-sdui-schema
***/
export default interface Schema {
container: {
style?: Record<string, any>,
},
card: {
@Tiagoperes
Tiagoperes / InvoiceResult.jsx
Last active January 26, 2020 19:56
Exemplo de contexto com leitura e escrita de dados
import React, { useState, useContext, useEffect } from 'react'
import useResouce from 'rest-resource'
import InvoiceTable from 'components/InvoiceTable'
import Pagination from 'components/Pagination'
import invoiceContext from './context'
import { Header, PreviousMonth, NextMonth } from './styled'
const InvoiceResult = () => {
const { page, setPage } = useState(1)
const {
@Tiagoperes
Tiagoperes / index.jsx
Created January 26, 2020 20:01
Exemplo usando props
import React, { useState } from 'react'
import YearMonthSelector from './YearMonthSelector'
import InvoiceResult from './InvoiceResult'
import InvoiceDispute from './InvoiceDispute'
const Invoice = () => {
const [year, setYear] = useState()
const [month, setMonth] = useState()
const [refetchInvoice, setRefetchInvoice] = useState()
const [selectedItem, setselectedItem] = useState()
@Tiagoperes
Tiagoperes / BeagleContextMiddleware.js
Last active February 12, 2020 19:28
Exemplos de middlewares para o beagle
// exemplo mais robusto: providencia um meio de acessar a árvore a partir do contexto do componente
// BeagleContextMiddleware.js
export const BEAGLE_ID_PREFIX = '_beagle_'
export function createBeagleContextMiddleware() {
let id = 1
const treeReferences = {}
const getTreeInContext = elementRef => treeReferences[elementRef.attributes.id]
@Tiagoperes
Tiagoperes / people.json
Last active February 21, 2020 18:00
family tree
[
{
"id":1,
"name":"Colton",
"lastName":"Baird",
"gender":"male",
"birthDate":"1880-01-14",
"deathDate":"1945-11-15",
"country":"French Polynesia"
},
@Tiagoperes
Tiagoperes / address.json
Created March 31, 2020 18:26
beagle forms
{
"_beagleType_": "container",
"id": "content",
"style": {
"width": "800px",
"height": "100%",
"display": "flex",
"justify-content": "space-around"
},
"children": [