Skip to content

Instantly share code, notes, and snippets.

View blasten's full-sized avatar

Emmanuel Garcia blasten

  • c.ai
  • Palo Alto, CA
View GitHub Profile
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<style>
!(function(t, i) {
"object" == typeof exports && "undefined" != typeof module
? (module.exports = i())
: "function" == typeof define && define.amd ? define(i) : (t.Layout = i());
})(this, function() {
"use strict";
function t(t, i, n) {
let e = S;
if (n) {
X.length = 0;
@blasten
blasten / diff.js
Last active August 23, 2017 01:35
Minimalistic tree diffing algorithm
export const OptCode = {
ADD_NODE: 1,
SET_PROPERTY: 2,
SET_TEXT: 3,
REMOVE_PROPERTY: 4,
REMOVE_NODE: 5
};
// a = new
// b = old
<template tag="video-playback-control">
<style>
:host {
display: block;
}
#playButton::slotted {
color: red;
}
</style>
<slot id="playButton" name="play-button"></slot>
const SENTINEL = -Infinity;
function groupEvents(events) {
if (!Array.isArray(events) || events.length === 0) {
return [];
}
events = events.slice();
events.sort((a, b) => a.start - b.start);
let group,
@blasten
blasten / CustomElement.js
Last active March 24, 2017 17:18
custom elements in Preact or React without CE polyfills.
const HAS_NATIVE_CE = window.customElements != null;
const HTMLElement = HAS_NATIVE_CE ? window.HTMLElement : class{ constructor(self) { return self; } };
export class CustomElement extends HTMLElement {
constructor(inst) {
this.__instance = super(inst);
return this.__instance;
}
get props() {
return Object.assign({}, this.__props);
// Input
function NumberPad({ onPadPressed } = props) {
let keys = [0, 1, 2, 3, 4, 5, 6, 7, 8];
return keys.map(digit => <button key={digit} onClick={(event) => { onPadPressed({ digit: digit }); }}>{key}</button>);
}
function Calculator({ result, set} = props) {
return <div style={{ backgroundColor: 'gray' }}>
<input type="text" readOnly="true" value={result} />
<NumberPad onPadPressed={(event) => {
export class SideBar extends HTMLElement {
static render({ name } = props) {
return <div>{name}</div>;
}
}
customElements.define('side-bar', SideBar);
export class ListView extends HTMLElement {
static render({ items } = props) {
_queue = [];
_isRunning = false;
async _runLoop(task) {
let job, queue = this._queue;
if (this._isRunning) {
// Preempt the current tasks
while (job = queue[0]) {
queue.shift();
! function(t, i) {
"object" == typeof exports && "undefined" != typeof module ? module.exports = i() : "function" == typeof define && define.amd ? define(i) : t.Layout = i()
}(this, function() {
"use strict";
function t(t) {
return new Promise(function(i, n) {
function s(h, o) {
try {
var r = t[o ? "throw" : "next"](h)