Skip to content

Instantly share code, notes, and snippets.

View clucasalcantara's full-sized avatar
🔥

Caio Alcantara clucasalcantara

🔥
View GitHub Profile

Keybase proof

I hereby claim:

  • I am clucasalcantara on github.
  • I am clucasalcantara (https://keybase.io/clucasalcantara) on keybase.
  • I have a public key whose fingerprint is 32C8 0014 F11E 7D87 FE96 69D0 6108 43C9 B8D6 2FCF

To claim this, I am signing this object:

@clucasalcantara
clucasalcantara / cart-reducer.js
Last active October 13, 2018 06:16
Cart Reducer
const actionTypes {
SHOW_ALL: 'CART/SHOW_ALL',
ADD_PRODUCT: 'CART/ADD_PRODUCT',
REMOVE_PRODUCT: 'CART/REMOVE_PRODUCT',
}
const cart = (state, action) => {
switch (action) {
case actionTypes.SHOW_ALL:
return state
@clucasalcantara
clucasalcantara / cart-add-product-ac.js
Last active October 13, 2018 05:51
Cart Add Product action creator
/**
* Product Example
*
* const product = {
* id: 'adsa-1234ds-123s',
* name: 'Batman Mask',
* price: 8.97,
* }
*/
@clucasalcantara
clucasalcantara / cart-state.js
Last active November 26, 2018 10:29
Cart State
const initialState = {
total: 0,
itemCount: 0,
products: []
};
@clucasalcantara
clucasalcantara / named-export.js
Last active September 16, 2018 07:00
Named export exemplification
const myFunctionToBeExported = () => {
alert('Hello Sir!')
}
export {
greet: myFunctionToBeExported,
myFunctionToBeExported,
}
// Importing
module.exports = {
lets: () => {},
make: () => {},
some: () => {},
magic: () => {}
}
// output
const x = require('./your_module')
console.log(x)
@clucasalcantara
clucasalcantara / default-export.js
Last active July 19, 2018 09:02
Default export
// single
export default a;
// object
export default {
count () {
return 'nooo';
},
increase (a) {
return a + 1;
Object.entries(PATO).map(value => {
const row = value[0].split('[')
const key = row[0]
const value1 = row[1].slice(0,-1)
const value2 = value[1]
return {
[key]: {
[value1]: [value2]
}
@clucasalcantara
clucasalcantara / shallowUntilTarget.js
Last active May 9, 2018 06:55
shallowUntilTarget - A helper to repeatedly render a component tree using enzyme.shallow() until it finds and render a TargetComponent: https://github.com/mozilla/addons-frontend/blob/58d1315409f1ad6dc9b979440794df44c1128455/tests/unit/helpers.js#L276
/*
* Repeatedly render a component tree using enzyme.shallow() until
* finding and rendering TargetComponent.
*
* This is useful for testing a component wrapped in one or more
* HOCs (higher order components).
*
* The `componentInstance` parameter is a React component instance.
* Example: <MyComponent {...props} />
*