Skip to content

Instantly share code, notes, and snippets.

View jonasantonelli's full-sized avatar
🏠
Working remotely

Jonas Antonelli jonasantonelli

🏠
Working remotely
View GitHub Profile
/**
Fullscreen Class
*/
class Fullscreen {
constructor() {
document.cancelFullScreen = document.webkitCancelFullScreen || document.mozCancelFullScreen || document.cancelFullScreen;
function flattenDeep(arr) {
return arr.reduce((acc, val) => Array.isArray(val) ? acc.concat(flattenDeep(val)) : acc.concat(val), []);
}
flattenDeep([[1,2,[3]],4]);
@jonasantonelli
jonasantonelli / reducer.js
Created July 17, 2019 18:25
Refactoring Reducer - First Version
import schema from './schema';
import { ACTIONS } from './action';
export default (state = schema, action) => {
switch (action.type) {
case ACTIONS.FETCHING:
return {
...state,
isFetching: true
@jonasantonelli
jonasantonelli / reducer.v2.js
Last active July 17, 2019 18:47
Refactoring Reducer - Second Version
import schema from './schema';
import { ACTIONS } from './action';
export default (state = schema, action) => {
switch (action.type) {
case ACTIONS.FETCHING_LIST:
return {
...state,
list: {
@jonasantonelli
jonasantonelli / reducer.v3.js
Created August 9, 2019 18:36
Refactoring Reducer
import schema from './schema';
import { ACTIONS } from './action';
const fetching = substate => (state, action) => {
return {
...state,
[substate]: {
...state[substate],
...action.value,
fetching: true
@jonasantonelli
jonasantonelli / styled-component-styled.jsx
Last active July 12, 2021 23:37
Styled Component - Using the shorthand tag name 'ul'
import styled from 'styled-components'
/*
* Using the shorthand tag name 'ul'
*/
const UnorderedList = styled.ul`
list-style: none;
li {
margin-bottom: 7px;
@jonasantonelli
jonasantonelli / styled-component-styled-component.jsx
Last active July 12, 2021 23:38
Styled-Components - Wrapping a custom component
import styled from 'styled-components'
/*
* Wrapping a custom component
*/
const UnorderedList = styled(({ children, ...rest }) => (
<ul {...rest}>
{ children }
</ul>
))`
@jonasantonelli
jonasantonelli / styled-component-styled-component-readable.jsx
Last active July 12, 2021 23:38
Styled-Components: Readable style
import styled, { css } from 'styled-components'
// Readable Style
const style = css`
list-style: none;
li {
margin-bottom: 7px;
}
`
@jonasantonelli
jonasantonelli / styled-component-styled-component-separating.jsx
Last active July 12, 2021 23:38
Styled Components - Extending Style
import styled, { css } from 'styled-components';
/**
* Extending from another component
*/
const List = styled.ul`
list-style: auto;
li {
text-transform: uppercase;
@jonasantonelli
jonasantonelli / styled-component-using.jsx
Last active July 12, 2021 23:08
Using Styled Component
import React from 'react';
import ReactDOM from 'react-dom';
import UnorderedList from './UnorderedList';
const App = () => (
<UnorderedList>
<li>Item X</li>
<li>Item Y</li>
</UnorderedList>
);