Skip to content

Instantly share code, notes, and snippets.

@dead-claudia
dead-claudia / api-redraw.js
Last active April 8, 2017 16:43
Mithril's api/redraw.js, rewritten to throttle globally, support sync redraws, and be simpler.
"use strict"
var coreRenderer = require("../render/render")
function throttle(callback) {
//60fps translates to 16.6ms, round it down since setTimeout requires int
var delay = 16, last = 0, pending
var timeout = typeof requestAnimationFrame === "function" ? requestAnimationFrame : setTimeout
return function() {
if (pending == null) {
@dead-claudia
dead-claudia / non-linear-control-flow.md
Last active May 1, 2017 15:47
A powerful non-linear control flow proposal unifying both Promise and Observable operations for highly expressive control flow and parallelism, inspired by non-Von Neumann models

Edit: The proposal now lives here, and this below is generally out of date.


Non-linear Control Flow

Asynchrony is hard. Modeling it is not super intuitive in most languages, JavaScript being no exception for the longest time. But we have been making progress:

  1. Callbacks give us the base concept, thanks to lambda calculus.
@dead-claudia
dead-claudia / mithril-optimization.md
Last active August 2, 2019 18:40
Mithril optimization ideas

Mithril Optimization Ideas

This is more of a list of ideas, so I can get some feedback on each one, but it's also in rough chronological order, since I have to wait for some things before I can do others. It deals a lot with optimization within the rendering, so be prepared to see some more arcane details about it and optimization in general.

I created this as a gist as to not litter the issue tracker with a long-term proposal likely to get lost in the flow of things.

  1. This monstrosity should be split up, so engines can actually optimize the thing better.

  2. This issue (#1653) should be fixed.

  • Compared to the rest, this is low hanging fruit.
import m from 'mithril'
import stream from 'mithril/stream'
import pointerStream from 'pointer-stream'
function targeted(state) {
const node = state._vnode.dom
const {x, y} = state._pointer.coords()
const child = document.elementFromPoint(x, y)
const parent = node.parentNode
@dead-claudia
dead-claudia / unicode-generate.js
Last active June 10, 2018 04:54
Unicode test function generator
#!/usr/bin/env node
"use strict"
// This generates one or more methods that check for a code point's existence
// within a set of code points, but with a few substantial optimizations - I'd
// rather not have a very slow or high-memory runtime test. Few more notes:
//
// - This exports the methods through an ES6 module. If you don't want that,
// you'll need to modify the script to change that.
// - At runtime, it stores all of its data in the smallest integer size it can
@dead-claudia
dead-claudia / express-server.js
Last active March 13, 2017 08:31
Sample server using stream function syntax (ported from my website's dev server)
import fs from "fs"
import path from "path"
import express from "express"
import stylus from "stylus"
import morgan from "morgan"
import autoprefixer from "autoprefixer-stylus"
import pugLocals from "./pug-locals.js"
import generateBlog from "./generate-blog-posts.js"
@dead-claudia
dead-claudia / observable-utility.js
Created February 11, 2017 09:29
A simple utility set for observables, featuring my stream function strawman
export function cast(observable) {
if (typeof observable === "function") {
return observable()
} else {
return observable
}
}
export stream function from(items) {
for (const item of items) emit item
@dead-claudia
dead-claudia / async-angular.js
Last active May 2, 2018 22:07
Proposed parallel async primitives, compared to callbacks + jQuery and RxJS + promises, using samples adapted from previous examples I found and used (I forget my sources...)
// Non-blocking async iterators + Angular 1
function searchWikipedia(term) {
return $http({
url: "http://en.wikipedia.org/w/api.php?&callback=JSON_CALLBACK",
method: "jsonp",
params: {
action: "opensearch",
search: encodeURI(term),
format: "json"
}
@dead-claudia
dead-claudia / on.es2017.js
Last active January 25, 2017 03:29
Thallium's `lib/reporter/on.js` with ES2017 equivalent.
import {Status} from "./util"
// Because ES5 sucks. (And, it's breaking my PhantomJS builds)
function setName(reporter, name) {
try {
Object.defineProperty(reporter, "name", {value: name})
} catch (e) {
// ignore
}
}
@dead-claudia
dead-claudia / test.es2017.js
Last active January 25, 2017 03:19
Thallium `lib/core/tests.js` with ES2017 equivalent
import {
Types,
Start, Enter, Leave, Pass, Fail, Skip, End, Hook,
Error as InternalError, HookError,
} from "./reports"
import {isOnly} from "./only"
/**
* The tests are laid out in a very data-driven design. With exception of the
* reports, there is minimal object orientation and zero virtual dispatch.