Skip to content

Instantly share code, notes, and snippets.

const makeQueue = () => {
let promise = Promise.resolve();
return function queue(asyncFn) {
promise = promise.then(() => asyncFn());
return promise;
};
};
const makeQueue = limit => {
const queue = [];
let concurrency = 0;
function enqueue(asyncFn) {
if (concurrency < limit) {
let curPromise = asyncFn().finally(() => {
concurrency -= 1;
const next = queue.shift();
@Ericnr
Ericnr / useLazyFragmentExample.js
Created May 7, 2021 16:43
useLazyFragment example
const FriendsList = props => {
const data = useFragment(
graphql`
fragment FriendsList_person on Person {
friends {
id
name
...FriendDetails_friend
}
}
@Ericnr
Ericnr / Todos.ts
Last active October 3, 2020 04:22
Todos
import {
Todos_viewer,
Todos_viewer$key,
} from './_generated_/Todos_viewer.graphql';
interface Props {
viewer: Todos_viewer$key;
}
export const Todos = ({ viewer }: Props) => {
const { todos }: Todos_viewer = useFragment(
graphql`
@Ericnr
Ericnr / useViewPort.ts
Created December 1, 2019 21:06
Get viewport with debounce
import { useState, useRef, useLayoutEffect, useMemo } from 'react';
function getVpWidth() {
return typeof window !== 'undefined'
? Math.max(
window.document.documentElement.clientWidth,
window.innerWidth || 0
)
: 0;
}