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 stringPixelWidth from "string-pixel-width"; | |
| export function getTextHeight(text, { textBlockWidth, lineHeight = 1.15, fontSize }) { | |
| const paragraphs = text.split('\n'); | |
| const lineCountPerParagraph = paragraphs.map(paragraph => { | |
| const words = paragraph.split(' '); | |
| const [lineCount] = words.reduce(([lines, line], word, idx) => { | |
| const expandedLine = line ? line + ` ${word}` : word; | |
| if (stringPixelWidth(expandedLine, {size: fontSize}) < textBlockWidth) { | |
| return [lines, expandedLine] |
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 React from "react"; | |
| import { configure, addDecorator } from "@storybook/react"; | |
| import styled from "styled-components"; | |
| import { MemoryRouter } from "react-router-dom"; | |
| import { ThemeService } from "services/theme"; | |
| const Center = styled.div` | |
| display: flex; | |
| justify-content: center; | |
| align-items: center; |
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 React, { | |
| useState, | |
| useCallback, | |
| useLayoutEffect, | |
| createContext, | |
| useContext, | |
| useMemo, | |
| } from 'react'; | |
| import qs from 'qs'; | |
| import { useLocation, useHistory } from 'react-router-dom'; |
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 blackBox() { | |
| var input = [0, 1, 2, 3, 4]; | |
| var results = []; | |
| for (var i = 0; i < input.length; i++) { | |
| results.push( | |
| new Promise(function(resolve) { | |
| setTimeout(function() { | |
| resolve(i); | |
| }, 200); | |
| }) |
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
| alert(); |
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 React, { Component } from "react"; | |
| import { observable, action } from "mobx"; | |
| import { inject, Provider, observer } from "mobx-react"; | |
| import "./App.css"; | |
| declare module "mobx-react" { | |
| type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>; | |
| type Diff<MasterObject extends SubObject, SubObject extends Object> = Omit< | |
| MasterObject, |
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 composeMiddleware(...middleware) { | |
| return (req, res, next) => middleware | |
| .reverse() | |
| .reduce( | |
| (next, mw) => | |
| () => mw(req, res, next), | |
| next | |
| )(); | |
| } |
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 React from 'react'; | |
| import { withRouter, Route } from 'react-router-dom'; | |
| const RelativeRoute = ({ match, path, ...props }) => <Route path={`${match.path}${path}`} {...props} />; | |
| export default withRouter(RelativeRoute); |
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 _ from 'lodash'; | |
| import { ObjectId } from 'mongoose'; | |
| import ensureObjectId from './utils'; | |
| exports default function ensureObjectIdProps(obj, paths) { | |
| paths.forEach(prop => { | |
| const currentValue = _.get(obj, prop); | |
| _.set(obj, prop, currentValue ? ensureObjectId(currentValue) : new ObjectId()); | |
| }); | |
| return obj; |
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 getPrivateContainer = () => { | |
| const privateProperties = new WeakMap(); | |
| const getPrivate = (instance, prop) => { | |
| if (!privateProperties.has(instance)) { | |
| privateProperties.set(instance, {}); | |
| } | |
| return privateProperties.get(instance)[prop]; | |
| }; | |
| const setPrivate = (instance, prop, value) => { | |
| if (!privateProperties.has(instance)) { |
NewerOlder