Skip to content

Instantly share code, notes, and snippets.

View 2020-02-22-delay-until.ts
import { concat, NEVER, Observable, OperatorFunction } from "rxjs";
import { buffer, mergeAll, publish, take } from "rxjs/operators";
function delayUntil<T>(notifier: Observable<any>): OperatorFunction<T, T> {
return source =>
publish(published =>
concat(published, NEVER).pipe(buffer(notifier), take(1), mergeAll()),
ruizb /
Last active Dec 30, 2020
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'
sledorze / Fold.ts
Last active Jun 29, 2019
Type safe Typescript definition of an ad'hoc Fold for a Tagged Sum Type (multiple tags supported)
View Fold.ts
// Definition
type Compact<A> = { [k in keyof A]: A[k] }
type FStruct<R extends Record<any, any>, K extends keyof R = keyof R> = {
[k in K]: { [kv in R[k]]: R extends { [r in k]: kv } ? Compact<R> : never }
type Match<StructK, R> = { [KV in keyof StructK]: (v: StructK[KV]) => R }
View share-replay-log.ts
import { defer, Observable } from "rxjs";
import { finalize, tap } from "rxjs/operators";
export const log = <T>(source: Observable<T>, name: string) => defer(() => {
console.log(`${name}: subscribed`);
return source.pipe(
next: value => console.log(`${name}: ${value}`),
complete: () => console.log(`${name}: complete`)
joshburgess / newtypes-redux-api-actions.ts
Last active Jan 26, 2019
Using newtype-ts newtypes to dynamically generate multiple API Action types representing API request states
View newtypes-redux-api-actions.ts
import { Predicate } from 'fp-ts/lib/function'
import { Prism } from 'monocle-ts'
import { Newtype, iso, prism, unsafeCoerce } from 'newtype-ts'
interface Optimistic<A extends string>
extends Newtype<
readonly Optimistic: unique symbol
readonly phantom: A
dsherret / find-unused-exports.ts
Last active Oct 28, 2020
Searches files for any exported declarations that aren't used in other files.
View find-unused-exports.ts
// this could be improved... (ex. ignore interfaces/type aliases that describe a parameter type in the same file)
import { Project, TypeGuards, Node } from "ts-morph";
const project = new Project({ tsConfigFilePath: "tsconfig.json" });
for (const file of project.getSourceFiles()) {
file.forEachChild(child => {
if (TypeGuards.isVariableStatement(child)) {
if (isExported(child))
bvaughn /
Last active Feb 25, 2021
How to use profiling in production mode for react-dom
bvaughn /
Last active Feb 27, 2021
Interaction tracing with React

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.

This Gist provides some high-level docum

bvaughn /
Last active Mar 1, 2021
Notes about the in-development React <Profiler> component


React 16.4 will introduce a new Profiler component (initially exported as React.unstable_Profiler) for collecting render timing information in order to measure the "cost" of rendering for both sync and async modes.

Profiler timing metrics are significantly faster than those built around the User Timing API, and as such we plan to provide a production+profiling bundle in the future. (The initial release will only log timing information in DEV mode, although the component will still render its children- without timings- in production mode.)

How is it used?

Profiler can be declared anywhere within a React tree to measure the cost of rendering that portion of the tree. For example, a Navigation component and its descendants:

joeporpeglia / app.jsx
Last active Feb 26, 2019
React Redux with the new React Context API. I didn't test this at all...
View app.jsx
import React from 'react';
import Counter from './counter';
const mapProps = ({ state, dispatch }) => ({
count: state,
increment: () => dispatch({
type: 'increment',
decrement: () => dispatch({