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 values = { | |
| foo: { | |
| foo: [ | |
| { | |
| foo: { | |
| foo: { | |
| foo: { | |
| foo: 'bar', | |
| }, | |
| }, |
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 useUnmountSafeReducer<R extends React.Reducer<any, any>>( | |
| reducer: R, | |
| initialState: React.ReducerState<R>, | |
| ): [React.ReducerState<R>, React.Dispatch<React.ReducerAction<R>>] { | |
| const [state, rawDispatch] = React.useReducer(reducer, initialState); | |
| const dispatchRef = React.useRef(rawDispatch); | |
| React.useEffect( | |
| (): (() => void) => (): void => { |
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
| class PersistentComponent extends React.PureComponent { | |
| static propTypes = { | |
| promise: PropTypes.object.isRequired, | |
| restore: PropTypes.function.isRequired, | |
| children: PropTypes.node, | |
| }; | |
| state = { | |
| pending: true, | |
| }; |
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 updateVisibility = state => { | |
| let childVisibility = state.childVisibility; | |
| let currentWidth = 0; | |
| state.children.forEach(element => { | |
| const key = element.props.key; | |
| const elementWidth = state.childWidths[key]; | |
| currentWidth += elementWidth; |
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
| // Recursive object set. | |
| const set = (object = {}, path, value) => path.length | |
| ? { | |
| ...object, | |
| [path[0]]: path.length > 1 | |
| ? set(object[path[0]],path.slice(1), value) | |
| : value, | |
| } | |
| : object; |
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
| // @flow | |
| // Import modules ============================================================== | |
| import * as React from 'react'; | |
| const buttonSizes = { | |
| small: { | |
| height: 32, | |
| fontSize: 14, | |
| padding: 12, |
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
| // @flow | |
| // ============================================================================= | |
| // Import modules. | |
| // ============================================================================= | |
| import {cloneElement} from 'react'; | |
| // SVG Elements with a default black fill. | |
| const DEFAULT_FILLED = new RegExp(`^${[ | |
| 'path', |
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 measureScrollbars = (): {width: number, height: number} => { | |
| const container = document.createElement('div'); | |
| container.style.width = '100px'; | |
| container.style.height = '100px'; | |
| container.style.overflow = 'scroll'; | |
| const liner = document.createElement('div'); | |
| liner.style.width = '200px'; | |
| liner.style.height = '200px'; |
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 patch = (target, func) => { | |
| const original = target[func]; | |
| target[func] = function () { | |
| return Promise.reolve(original.apply(this, arguments)); | |
| }; | |
| } | |
| const targets = [ | |
| [window, 'fetch'], |
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
| // @flow | |
| type Result<T> = { | |
| url: string; | |
| status: number; | |
| body: T; | |
| }; | |
| type Handlers<T = mixed> = [ | |
| (Response) => Promise<Result<T>>, |