Skip to content

Instantly share code, notes, and snippets.

View modernserf's full-sized avatar

Justin Falcone modernserf

View GitHub Profile
@modernserf
modernserf / 1.naive-immutable-record.js
Last active August 23, 2019 22:00
Immutable Records with value equality in JS
const lookupTable = []
export function record (fields) {
for (const storedRecord of lookupTable) {
if (shallowEqual(fields, storedRecord)) {
return storedRecord
}
}
const newRecord = Object.freeze({ ...fields })
lookupTable.push(newRecord)
@modernserf
modernserf / immutable-record.js
Last active December 11, 2018 17:55
Notes for "The Tyranny of Triple-Equals"
let lookupTable = Immutable.Map({})
export function record (fields) {
let key = Immutable.Map(fields)
let storedValue = lookupTable.get(key)
if (storedValue) { return storedValue }
let newValue = Object.freeze({ ...fields })
lookupTable = lookupTable.set(key, newValue)
return newValue
}
const isolate = (scope) =>
new Proxy(scope, {
has: () => true,
get: (target, key) => {
if (key === Symbol.unscopables) {
return undefined
}
if (key in target) {
return target[key]
}
@modernserf
modernserf / resumable-errors.js
Created January 11, 2019 02:05
Common Lisp-style resumable errors with generators
function * example (resource) {
resource.open()
yield _finally(function * () {
resource.close()
})
yield _catch(function * (error) {
if (error.message === 'foo') {
return resume('bar')
}
@modernserf
modernserf / 1.readme.md
Last active March 5, 2021 18:44
Tagged Template Binding Literals

(Tagged) Template Binding Literals

This proposal defines new syntax for destructuring binding with tagged template literals.

Status

Not submitted.

Introduction

@modernserf
modernserf / context.md
Last active March 24, 2019 17:46
The React Context API in an alternate universe

The React Context API in an alternate universe

Overview

Context is "just" a prop with special behavior, like children or key. It implicitly propagates from elements to their children, unless it is explicitly overridden.

Context can be provided as a prop (to elements) or via the children object's withContext method. Context can be consumed as a prop (to components) or by using a function in children.

This component:

@modernserf
modernserf / anon-imperative.jsx
Last active May 25, 2019 14:04
Two approaches to handling imperative code in react
function useTransition (isActive, onEnter = noop, onExit = noop) {
const ref = useRef()
useEffect(() => {
if (!ref.current) return
if (isActive) onEnter(ref.current) else onExit(ref.current)
}, [isActive])
return ref
}
// -----
@modernserf
modernserf / Refs.md
Created August 23, 2019 21:15
Code is a User Interface references

Zebu https://github.com/modernserf/zebu

Constraints - Crista Lopes tagide.com/blog/research/constraints

Little Languages - Jon Bentley staff.um.edu.mt/afra1/seminar/little-languages.pdf

Purpose-Built Languages - Mike Shapiro

@modernserf
modernserf / build.module.js
Last active September 10, 2019 18:34
How do I get the styled components plugin to work here?
// This code should have been transformed, right??
import styled from 'styled-components';
const Foo = styled.div`
color: pink;
`;
export { Foo };
:- discontiguous gender/2.
:- discontiguous balls/2.
:- discontiguous age/2.
:- discontiguous gender_pair/2.
:- discontiguous position/2.
% positions: [sled] -> wheel -> team -> swing -> lead
% TODO: what is the significance of the wind?
% hari