Skip to content

Instantly share code, notes, and snippets.

View itsMapleLeaf's full-sized avatar

Darius itsMapleLeaf

View GitHub Profile

response to https://gist.github.com/amcdnl/b52e9dd11850eeb8de8f

Not Standard

TS abides strictly by ES standards and doesn't add any new syntax features for the language. this is a pivot from how things worked back then, and a good one. TS still has some language features left behind from "the olden days", but they're largely avoided (outside of Angular, but that's more of a criticism at angular than TS)

Not Community Driven

I don't have a strong opinion when it comes to how "community driven" some projects should be, but TS is receiving fast progress on things people really like, so I'd say the project is managed well

type Await<T> = T extends Promise<infer V> ? Await<V> : T
type AwaitObject<Promises extends Record<string, Promise<unknown>>> = {
[K in keyof Promises]: Await<Promises[K]>
}
async function awaitObject<Promises extends Record<string, Promise<unknown>>>(
promises: Promises,
) {
const pairs = await Promise.all(
@itsMapleLeaf
itsMapleLeaf / lazyNamed.ts
Created June 11, 2021 16:13
lazyNamed - React.lazy but for named exports
import * as React from 'react'
export function lazyNamed<
Name extends string,
Component extends React.ComponentType<unknown>
>(
loader: () => Promise<Record<Name, Component>>
name: Name,
): React.LazyExoticComponent<Component> {
return React.lazy(() => loader().then((mod) => ({ default: mod[name] })))
@itsMapleLeaf
itsMapleLeaf / example.js
Last active June 9, 2021 04:18
js arrow function syntax
// good
items.map(item => {
return <div />
})
// good - implicit return, doesn't require curly braces {} or return keyword
items.map(item => <div />)
// good - using parens when on multiple lines is a common convention
items.map(item => (
@itsMapleLeaf
itsMapleLeaf / framework.ts
Last active May 29, 2021 23:44
command framework ideas
export type BlockContext = {
command: <Args extends ArgType<unknown>[]>(
// using this [...Args] makes it infer a tuple for some reason, TS is weird
options: CommandOptions<[...Args]>
) => void
}
export type CommandOptions<Args extends ArgType<unknown>[]> = {
name: string
description: string
@itsMapleLeaf
itsMapleLeaf / useEqualityMemo.ts
Last active May 21, 2021 16:36
useEqualityMemo
import { circularDeepEqual } from "fast-equals"
import { useRef } from "react"
/**
* like `useMemo()`, but with a custom comparer.
* Useful for making objects stable with useEffect() and friends
*
* @param value The value to be memo'd
* @param isEqual Whether or not to use the new value.
* If the value changes according to this isEqual function,
@itsMapleLeaf
itsMapleLeaf / README.md
Last active May 24, 2024 03:53
Typed remix helpers

This is no longer needed! Remix's built-in types have improved significantly. But I'll keep this here for historical reasons.


Typed helpers for low-boilerplate type inference with Remix data.

  • I suffix them with *Typed so I don't accidentally import the core remix helpers.
  • This doesn't support regular Response objects to prevent accidentally using them with the typed helpers.
@itsMapleLeaf
itsMapleLeaf / tailwind-drama-thought-gathering.md
Created May 8, 2021 18:25
tailwind drama thought gathering (as a tailwind user)

there's a lot of sides and complexities to this, but here's what I think:

  • sharing articles criticizing tailwind is good and fine, people do that all the time
  • this article in particular was the wrong article to share. it's bashing based off of a factually incorrect premise, plain and simple
  • sara shouldn't have shared that article as if it were valid or worth anyone's time
  • adam's responses that sara was "spreading negativity" weren't entirely in the wrong
  • I kind of feel for adam; it's rough and awkward having gone from "guy with a weird fringe idea" to "owner of framework and business that's quickly eating half of the frontend ecosystem". he doesn't have the right mindset or experience to handle all of the sudden attention, especially since TW goes hard against things people've been taught for several years

on the flipside:

@itsMapleLeaf
itsMapleLeaf / script.js
Created April 28, 2021 15:02
node code cleanup
const fs = require("fs")
const fsPromises = require("fs/promises")
;(async () => {
try {
// passing utf-8 here (the encoding argument) makes it return a string
const fileList = await fsPromises.readFile("./exclude", "utf-8")
const excludeList = fileList.split("\n")