Skip to content

Instantly share code, notes, and snippets.

View krinoid's full-sized avatar
🛰️

krinoid krinoid

🛰️
View GitHub Profile
@booya2nd
booya2nd / mock-esmodule.js
Last active September 28, 2023 12:50
mockESModule workaround for JEST 29.x
import * as path from 'path';
import * as url from 'url';
function forEachDeep(obj, cb, options = { depth: 6 }) {
(function walk(value, property = undefined, parent = null, objPath = []) {
return value && typeof value === 'object' && objPath.length <= options.depth
? Object.entries(value).forEach(([key, val]) =>
walk(val, key, value, [...objPath, key])
)
: cb([property, value], parent, objPath);
@sindresorhus
sindresorhus / esm-package.md
Last active June 14, 2024 06:33
Pure ESM package

Pure ESM package

The package that linked you here is now pure ESM. It cannot be require()'d from CommonJS.

This means you have the following choices:

  1. Use ESM yourself. (preferred)
    Use import foo from 'foo' instead of const foo = require('foo') to import the package. You also need to put "type": "module" in your package.json and more. Follow the below guide.
  2. If the package is used in an async context, you could use await import(…) from CommonJS instead of require(…).
  3. Stay on the existing version of the package until you can move to ESM.
@brentjanderson
brentjanderson / Procfile
Last active May 23, 2024 19:33
Running RedwoodJS on Heroku
release: yarn rw prisma migrate deploy
web: bin/start-nginx node index.js
🚶‍♂️ 23km █████████████▏░░░░░░
‍🏃‍♂️ 12km ██████▌░░░░░░░░░░░░░
🚴‍♂️ 0km ░░░░░░░░░░░░░░░░░░░░
34km total
@ruizb
ruizb / advanced-example.md
Last active September 26, 2023 20:21
Reader monad example using fp-ts

The following section is not part of monet.js documentation, but I think it's worth showing how we can compose readers using fp-ts.

Reader composition

Let's say we have the following piece of code:

interface Dependencies {
  logger: { log: (message: string) => void }
 env: 'development' | 'production'
@mfellner
mfellner / graphql.ts
Created July 8, 2019 20:42
Using Apollo Server in Next.js 9 with API route in pages/api/graphql.ts
import { ApolloServer, gql } from 'apollo-server-micro';
const typeDefs = gql`
type Query {
sayHello: String
}
`;
const resolvers = {
Query: {
import React, { Suspense, useState } from "react";
import { unstable_createResource as createResource } from "react-cache";
import {
Combobox,
ComboboxInput,
ComboboxList,
ComboboxOption
} from "./Combobox2.js";
function App({ tabIndex, navigate }) {
@bvaughn
bvaughn / index.md
Last active June 13, 2024 22:28
How to use profiling in production mode for react-dom

React recently introduced an experimental profiler API. This page gives instructions on how to use this API in a production release of your app.

Table of Contents

Profiling in production

React DOM automatically supports profiling in development mode for v16.5+, but since profiling adds some small additional overhead it is opt-in for production mode. This gist explains how to opt-in.

@bvaughn
bvaughn / index.md
Last active April 3, 2024 07:41
Interaction tracing with React

This API was removed in React 17


Interaction tracing with React

React recently introduced an experimental profiler API. After discussing this API with several teams at Facebook, one common piece of feedback was that the performance information would be more useful if it could be associated with the events that caused the application to render (e.g. button click, XHR response). Tracing these events (or "interactions") would enable more powerful tooling to be built around the timing information, capable of answering questions like "What caused this really slow commit?" or "How long does it typically take for this interaction to update the DOM?".

With version 16.4.3, React added experimental support for this tracing by way of a new NPM package, scheduler. However the public API for this package is not yet finalized and will likely change with upcoming minor releases, so it should be used with caution.