Skip to content

Instantly share code, notes, and snippets.

View phpnode's full-sized avatar

Charles Pick phpnode

View GitHub Profile
type Linkable = {
name: string,
profileURL: string
};
function bigOldObject () {
return {
id: 1,
name: 'foo',
email: 'foo@bar.com',
// paste me into https://codemix.github.io/flow-runtime/#/try
// (no gist support yet :( )
import t, {reify} from 'flow-runtime';
type ValidURL = string;
(reify: ValidURL).addConstraint(url => {
if (/^(.|\/)/.test(url)) {
return "Don't use relative URLs for some reason";
@phpnode
phpnode / demo.js
Created January 19, 2018 18:25
Extension methods for JS using proxies!
// @flow
const proxyCache = new WeakMap();
const extensionMethods = new WeakMap();
function extended<T>(instance: T): $Supertype<T> {
if (isPrimitive(instance)) {
return instance;
}
const existingProxy = proxyCache.get(instance);
const invalidMatchSignal = new Error();
function makeProxyThrower(input) {
return new Proxy(input, {
get(target, prop, receiver) {
if (prop in target) {
const result = Reflect.get(target, prop, receiver);
if (typeof result === "object" && result !== null) {
return makeProxyThrower(result);
@phpnode
phpnode / machine.js
Created July 22, 2020 09:19
Generated by XState Viz: https://xstate.js.org/viz
function createApprovalMachine(context) {
return Machine({
id: 'approval',
initial: 'initializing',
context,
states: {
initializing: {
on: {
'': [
@phpnode
phpnode / esx.md
Created November 8, 2022 12:53 — forked from WebReflection/esx.md
Proposal: an ESX for JS implementation

About

In a quest to explore improvements over common JSX transformers I have managed to find great performance able to compete with template literal based libraries.

In this document I would like to describe, via JS itself, and as PoC, how JSX could be both rebranded as ESX and improved.

Goal

Differently from E4X, but also differently from JSX, this proposal leaves developers provide their own "render" implementation, freeing ESX usage from any previous attempt to confine JSX or E4X into the DOM world, where it's been proven, in the JSX case, it's not really where it belongs, as it can be used as neutral DSL.