Skip to content

Instantly share code, notes, and snippets.

@dbuenzli
dbuenzli / ocamlib.md
Last active August 22, 2022 07:38
OCaml compiler support for library linking
@jordwalke
jordwalke / gist:c60c91ff6c82d47bf605
Created August 25, 2014 07:17
Simple Module React OCaml API
(* Same example as https://gist.github.com/jordwalke/67819c91df1552009b22
but using OCaml's simple module feature (every file is a module) *)
open ReactDOM
(* Component Properties *)
type props = {count: int}
(* Hey, state can be any type! *)
type state = string
@jordwalke
jordwalke / myComponent.ml
Last active December 13, 2021 17:32
React OCaml API
open ReactDOM
module MyComponent = struct
(* Component Properties *)
type props = {count: int}
(* Hey, state can be any type! *)
type state = string
(* Initializer *)

Virtual DOM and diffing algorithm

There was a [great article][1] about how react implements it's virtual DOM. There are some really interesting ideas in there but they are deeply buried in the implementation of the React framework.

However, it's possible to implement just the virtual DOM and diff algorithm on it's own as a set of independent modules.

@creationix
creationix / run.js
Last active March 7, 2017 18:36
universal callback/continuable/thunk generator runner
function run(generator) {
// Pass in resume for no-wrap function calls
var iterator = generator(resume);
var data = null, yielded = false;
next();
check();
function next(item) {
var cont = iterator.next(item).value;