This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const raff = (render, raf = window.requestAnimationFrame) => { | |
let redraw = false | |
let args = null | |
return (...yargs) => { | |
if (args === null && !redraw) { | |
redraw = true | |
raf(() => { | |
redraw = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const app = require('express')(); | |
const http = require('http').Server(app); | |
const io = require('./io.js')(http); | |
io.on('connection', socket =>{ | |
console.log('someone connected'); | |
socket.on('start', msg => { | |
io.emit('message', msg); | |
}); | |
socket.on('disconnect', () => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const connect = store => litElement => | |
class extends litElement { | |
connectedCallback() { | |
if (super.connectedCallback) { | |
super.connectedCallback(); | |
} | |
this._storeUnsubscribe = store.subscribe(() => this.stateChanged(store.getState())); | |
this.stateChanged(store.getState()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const path = require('path'); | |
const http = require('http'); | |
const root = path.resolve('./dist'); | |
const server = http.createServer((req, res) => { | |
const file = path.join( | |
root, | |
path.normalize(req.url).replace(/^(\.\.[\/\\])+/, '') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let _id = 0; | |
let cache = {}; | |
const uuid = () => 'x' + (_id++).toString(36); | |
const sheet = new CSSStyleSheet(); | |
const css = css => { | |
const className = cache[css] || uuid() | |
const cached = !!cache[css] | |
cache[css] = className |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let _id = 0 | |
export const uuid = () => 'x' + (_id++).toString(36) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { createContext, useContext, useState } from 'react' | |
export const createStore = initialState => { | |
const context = createContext(initialState) | |
const { Provider } = context | |
let currentState = initialState | |
let setState = value => Object.assign(currentState, value) | |
const useStore = () => [useContext(context), setState] | |
const Provider = ({ children }) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
class Component extends React.Component { | |
state = this.props.initialState; | |
_setState = (...args) => this.setState(...args); | |
_forceUpdate = (...args) => this.forceUpdate(...args); | |
getArgs() { | |
const { | |
state, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Libraries | |
import React, { Component, createElement } from "react"; | |
import { from, throwError } from "rxjs"; | |
import { map, distinctUntilChanged } from "rxjs/operators"; | |
// A Component to subscribe to observable streams | |
export class Stream extends Component { | |
subscription = null; // keep track of our subscription | |
_isMounted = false; // keep track if we have mounted, used in subscription to set initial state |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const useConfirm = text => { | |
const [did, setDid] = useState(false) | |
const [show, setShow] = useState(false) | |
useEffect(() => { | |
if (show) { | |
setDid(confirm(show)) | |
setShow(false) | |
} | |
}, [show]); | |
return [did, (t = text) => setShow(t)]; |