Instantly share code, notes, and snippets.

View prng.js
const prng = ((seed, size, value = seed % size) => () => ((value = value * 16807 % size - 1) - 1) / size)(4022871197, 2147483647)
View index.js
'use strict'
var h1 = function (tag, props, children) {
return {tag: tag, props: props, children: children}
}
var h2 = function (tag, props, children) {
return {tag: tag, props: props, children: children, 9: ''}
}
View polymorphism-access.js
const N = 10000;
const FOO = 'foo';
function test(fn) {
var result;
for (var i = 0; i < N; ++i) result = fn();
return result;
}
test(x => x);
View worker.html
<script id="worker" type="worker">
importScripts('https://unpkg.com/dio.js')
const shared = {memory: {}, address: 0}
const allocateMemory = (object) => {
shared.memory[shared.address] = object
return shared.address++
}
View ast.js
function Stack () {
this.next = this
this.prev = this
this.length = 0
}
Stack.prototype = {
/**
* @param {Object} node
* @param {Object} before
View interface.ts
interface Virtual {
merge(Virtual)
}
interface VirtualStyle extends Virtual {
merge(VirtualStyle)
}
interface VirtualProperties extends Virtual {
style: VirtualStyle
View talk.md

A Journey Into Building a Fast Text Editor With JS & Canvas!

Text editors have a way of looking simple but managing and painting text is no small task, this talk will give us a look into what bits(literaly) and pieces go into making a fast text editor with Javascript & Canvas. We'll look into what format the text you type is stored in, how it's mutated and highlighted, and how all of this is translated onto a canvas in less than the time it takes you to blink. As a by product we'll get to see how a regular expression engine is implementated and why games use draw distance to save precious hardware resources.

View VDOM-impl.js
var length = 1024*100; // enough to store 100kb of instrutions at any time
var action = new Uint8Array(length);
var memory = new Array(length);
// action carry instructions with pointers to memory for where to find the nodes to act on
// memory carries nodes that exist in memory
// for example
View frameScheduler.js
function frameScheduler (fps) {
var highPriWork = [];
var lowPriWork = [];
var highPriWorkLen = 0;
var lowPriWorkLen = 0;
var frameBudget = 1000 / fps;
var lastTime = 0;
var asyncCallback;
var Promise = window.Promise;
View frameLoop.js
/**
* @param fn {Function} Callback function to trigger on frame
* @param fps {int} Target FPS
* @returns {{pause: pause, start: start, destroy: destroy}}
*/
function frameLoop(fn, fps=60) {
let then = 0;
let interval = 1000 / fps;
let isRunning = true;
let currentFrameId = null;