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
export default function executeSequentialPromises(funcs) { | |
return funcs.reduce( | |
(promise, func) => | |
promise.then(result => | |
(func() || Promise.resolve(undefined)).then( | |
Array.prototype.concat.bind(result) | |
) | |
), | |
Promise.resolve([]) | |
) |
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" | |
/** | |
* consider the object | |
* | |
* const obj = { | |
* key1: value1 | |
* key2: value2 | |
* "key3,key4,key5": {key3: value3, key4: value4} | |
* } | |
* |
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
require = require("esm")(module) | |
module.exports = require("./server") |
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 _ from "lodash" | |
/** | |
* Provided that a list of providers [P1, P2, P3, P4] is passed as props, | |
* it renders | |
* | |
* <P1> | |
<P2> | |
<P3> |
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, useContext, useMemo } from "react" | |
export default function getContextManager() { | |
const Context = React.createContext() | |
function Provider(props) { | |
const [state, setState] = useState() | |
const api = useMemo(() => [state, setState], [JSON.stringify(state)]) | |
return <Context.Provider value={api}>{props.children}</Context.Provider> | |
} |
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 { useState, useEffect, useRef } from "react" | |
export default function useNewEntries({ entries }) { | |
const [newEntries, setNewEntries] = useState([]) | |
const oldEntries = useRef(entries) | |
useEffect(() => { | |
if (_.isEmpty(entries)) return | |
const newEntries = entries.filter(entry => |
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 useRouter from "use-react-router" | |
import { matchPath } from "react-router-dom" | |
export default function useParams(path) { | |
const { location } = useRouter() | |
const { pathname } = location | |
const pattern = `(.*)?${path}` | |
const match = matchPath(pathname, { path: pattern }) || {} |
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 useRouter from "use-react-router" | |
import { join } from "path" | |
import { matchPath } from "react-router-dom" | |
export default function useMatchPath(path) { | |
const { location } = useRouter() | |
const pathname = _.get(location, "pathname") | |
const match = matchPath(pathname, { path: join("(.*)?", 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 LIST = gql` | |
query List($category: String!) { | |
list(category: $category) { | |
id | |
description | |
} | |
} | |
` | |
const [list, setList] = useAppState({ |
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 useCount({ label }) { | |
const COUNT = gql` | |
query Count($label: ID) { | |
count(label: $label) @client | |
} | |
` | |
const [count, setCount] = useAppState({ | |
query: COUNT, | |
variables: { label } |
NewerOlder