An exploration of the different render methods available in react-enzyme.
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 _ = require("highland"); | |
const { Readable } = require("stream"); | |
const wrapAsync = require("./wrap-async"); | |
const sleep = (duration) => | |
new Promise((resolve) => setTimeout(resolve, duration)); | |
class Counter extends Readable { | |
constructor(opt) { | |
super(opt); |
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
// The docs for mongodb native driver sessions are pretty bare. The best example I can find is | |
// https://www.mongodb.com/blog/post/quick-start-nodejs--mongodb--how-to-implement-transactions | |
// but the code is generally not pretty; I think the following is likely the most suitable API: | |
// const doc = withTransaction(async session => { | |
// const doc = await users.updateOne({ _id: id }, { $set: { email } }, { returnOriginal: false, session }); | |
// await orders.updateMany({ email }, { $set: { userId: id } }, { session }); | |
// return doc; | |
// }); | |
const withTransaction = async <T>( | |
fn: (session: ClientSession) => Promise<T> |
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
interface TErrorOptions<Info, Cause> { | |
readonly msg?: string; | |
readonly info?: Info; | |
readonly cause?: Cause; | |
} | |
class TError<Info, Cause extends Error> extends Error { | |
public info?: Info; | |
public cause?: Cause; | |
constructor({ msg, cause, info }: TErrorOptions<Info, Cause>) { |
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 requestNextAnimationFrame = (callback: FrameRequestCallback) => { | |
const handles: number[] = []; | |
const requestThisAnimationFrame = (callback: FrameRequestCallback) => { | |
handles.push(window.requestAnimationFrame(callback)); | |
}; | |
requestThisAnimationFrame(() => requestThisAnimationFrame(callback)); | |
return () => handles.forEach(handle => window.cancelAnimationFrame(handle)); | |
}; | |
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 React, { | |
createContext, | |
useState, | |
useCallback, | |
useMemo, | |
useContext, | |
useId, | |
useLayoutEffect, | |
useEffect, | |
} from "react"; |
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 { parse } from 'cache-control-parser'; | |
export default { | |
async fetch(request: Request, env: {}, ctx: ExecutionContext): Promise<Response> { | |
try { | |
const cache = await caches.default; | |
const cachedResponse = await cache.match(request); | |
if (cachedResponse) { | |
console.log('Cache: HIT'); | |
if (shouldRevalidate(cachedResponse)) { |
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
.box { | |
display: block; | |
background: red; | |
width: 200px; | |
height: 200px; | |
opacity: 1; | |
} | |
.box-hidden { | |
display: none; |
OlderNewer