This file contains 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* range(fromInclusive, toExclusive, step = 1) { | |
if (toExclusive == undefined) { | |
toExclusive = fromInclusive; | |
fromInclusive = 0; | |
} | |
for (let i = fromInclusive; (toExclusive - i) * step > 0; i += step) { | |
yield i; | |
} | |
} |
This file contains 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 shouldAddB = true; | |
let obj = {a:1, ...(shouldAddB && {b:2})}; |
This file contains 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 React from "react"; | |
type Value = boolean; | |
type ContextWithSetter = React.Context<{ | |
value: Value; | |
setValue: (value: Value) => void; | |
}>; | |
const { Provider, Consumer }: ContextWithSetter = React.createContext({ |
This file contains 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
getPackageNames(input) { | |
// you don't need the global array and mutate it later. The map method will create a new array for you ;) | |
if (!input) { | |
return Promise.resolve({ options: [] }); | |
} | |
return fetch(`https://api.npms.io/v2/search?q=${input}`) | |
.then(response => response.json()) | |
// the map method will | |
// 1. create a new array |
This file contains 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 setup(propOverrides = {}) { | |
const defaultProps = { | |
onChange: jest.fn(), | |
renderBlockContent: jest.fn(), | |
value: [{ content: 'Test 1' }, { content: 'Test 2' }] | |
}; | |
const mergedProps = { | |
...defaultProps, | |
...propOverrides |