Skip to content

Instantly share code, notes, and snippets.

View ezekielchentnik's full-sized avatar

Ezekiel Chentnik ezekielchentnik

View GitHub Profile
@ezekielchentnik
ezekielchentnik / glued.js
Created July 16, 2019 13:40
naive global state in react
import React, { Component } from 'react';
class State {
constructor() {
this.state = {};
this.subscriptions = [];
}
subscribe(cb) {
this.subscriptions.push(cb);
@ezekielchentnik
ezekielchentnik / 1k.js
Last active July 14, 2019 20:38
replace react
let I = 'data-id'
let s = 'string'
let n = 'number'
let d = document
let O = Object
let a = (el, x) =>
x.reduce((e, c) => {
e.appendChild(c instanceof HTMLElement ? c : d.createTextNode(c))
return e
@ezekielchentnik
ezekielchentnik / $.js
Created July 13, 2019 02:09
reusable query selector helper
const $ = q => (els => els.length > 1 ? els : els[0])(document.querySelectorAll(q))
{
"name": "rollup-kitchensink",
"version": "0.0.0",
"description": "Kitchensink of rollup plugins",
"author": "Ezekiel Chentnik",
"license": "MIT",
"scripts": {
"test": "echo write tests yo"
},
"dependencies": {
export class Static extends React.Component {
shouldComponentUpdate() {
return false;
}
render() {
var child = this.props.children;
if (child === null || child === false) {
return null;
function mainView (state, emit) {
return html`
<body>
<h1>count is ${state.count}</h1>
<button onclick=${onclick}>Increment</button>
</body>
`
function onclick () {
emit('increment', 1)
const microtask = () => {
let node = document.createTextNode(''),
queue = [],
i = 0
new window.MutationObserver(() => {
while (queue.length) queue.shift()()
}).observe(node, { characterData: true })
return fn => {
function nanotask (cb) {
Promise.resolve().then(cb)
}
var createView = function(update) {
var increase = function(amount) {
return function(_event) {
update(amount);
};
};
var view = function(model) {
return (<div>
<div>Counter: {model}</div>
const raff = (render, raf = window.requestAnimationFrame) => {
let redraw = false
let args = null
return (...yargs) => {
if (args === null && !redraw) {
redraw = true
raf(() => {
redraw = false