This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"name": "Favorites", | |
"list": ["7fo5v_QH-MI", "7fo5v_QH-MI", "7fo5v_QH-MI", "gTRnWBZdOfY"] | |
}, | |
{ | |
"name": "Vinyasa", | |
"list": [ | |
"7fo5v_QH-MI", | |
"7fo5v_QH-MI", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"React Functional Component": { | |
"prefix": "crfc", | |
"body": [ | |
"import React from 'react';", | |
"", | |
"interface ${1:${TM_FILENAME_BASE}}Props {}", | |
"", | |
"const ${1:${TM_FILENAME_BASE}}: React.FC<${1:${TM_FILENAME_BASE}}Props> = (props) => {", | |
"", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as R from 'ramda' | |
const foods = [{item: 'bread', calories: 500},{item: 'cheese', calories: 300},{item: 'ham', calories: 200}] | |
const getTotalCalories = R.compose(R.reduce(R.add,0),R.map(R.prop('calories'))) | |
console.log(getTotalCalories(foods)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Asserts data is an array of values that pass a certain check | |
// Once the assertion passes (not throwing), TS will infer the proper type | |
function assertIsTypedArray<T>(arg: any, check: (value: any) => value is T): asserts arg is T[] { | |
if (!Array.isArray(arg)) throw new Error(`This is not an array: ${JSON.stringify(arg)}`); | |
if (arg.some((el) => !check(el))) | |
throw new Error(`Some elements of the array are not the expected type: ${JSON.stringify(arg)}`); | |
} | |
// exemple of check function |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Composes a function that returns the result of invoking the given functions | |
* with the `this` binding of the created function, where each successive | |
* invocation is supplied the return value of the previous. | |
**/ | |
export function pipe(...funcs) { | |
const length = funcs.length; | |
let index = length; | |
while (index--) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare module 'module' { | |
const noTypesYet: any; | |
export default noTypesYet; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function useDeepCompareMemoize(value) { | |
const ref = React.useRef() | |
if (!deepEqual(value, ref.current)) { | |
ref.current = value | |
} | |
return ref.current | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const usePrevious = value => { | |
const ref = useRef(); | |
useEffect(() => { | |
ref.current = value; | |
}); | |
return ref.current; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function uniq(array) { | |
return array.filter( | |
(obj, index, self) => index === self.findIndex(el => el.label === obj.label) | |
); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// compares 2 arrays | |
const arraysEqual = (a, b) => { | |
if (a === b) return true; | |
if (a == null || b == null) return false; | |
if (a.length !== b.length) return false; | |
// compare that both contains same elements no matter the order (optional) | |
const aSort = a.sort(); | |
const bSort = b.sort(); |
NewerOlder