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
https://diep.io?p=f712ef3873ba4118a90ddc04245cf08c01c04f1c |
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 type Effect = { type: string; value?: any } | |
export type State<T> = T | |
const get: Effect = { type: 'GET' } | |
const put = (value: any): Effect => ({ type: 'PUT', value }) | |
const runState = <T>( | |
genFn: () => Generator<Effect, void, State<T>>, | |
initialState: State<T>, | |
) => { |
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, { useState, useEffect } from 'react' | |
const findByAttr = (attr, mutations) => mutations.find(m => m.attributeName === attr) | |
const isBlockerTarget = mutation => 'intransigentBlockerTarget' in mutation.target.dataset | |
const IntransigentBlocker = props => { | |
const [id] = useState(+new Date) | |
useEffect(() => { | |
const observer = new MutationObserver(mutations => { |
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 { random, floor } = Math | |
const CatSack = Object.assign( | |
(...cats) => ({ pull: () => cats[floor(random() * cats.length)] }), | |
{ of: (...args) => CatSack(...args) } | |
) | |
const sack = CatSack.of('Oof', null, {}) | |
sack.pull() |
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 withTimeout = (time, f) => (...args) => ( | |
Promise.race([ | |
new Promise((_, reject) => setTimeout(reject, time, 'TIMEOUT')), | |
f(...args) | |
]) | |
) |
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
signatureToTypes = sig => sig | |
.split(' -> ') | |
.map(type => ({ | |
Number: { | |
ctor: Number, | |
type: 'number', | |
}, | |
Object: { | |
ctor: Object, | |
type: 'object', |
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 createSlidingPuzzle = (target, size = 50) => { | |
const shuffle = arr => arr.slice().sort(() => Math.random() > .5) | |
const shuffleAll = table => shuffle(table).map(shuffle) | |
const render = table => ( | |
table.forEach( | |
(column, y) => column | |
.map((value, x) => !!value ? createTile(value, x, y) : document.createElement('div')) | |
.forEach(tile => target.appendChild(tile)) | |
) |
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
// phone only | |
@media (max-width: 599px) { | |
} | |
// tablet portrait up | |
@media (min-width: 600px) { | |
} | |
// tablet landscape up | |
@media (min-width: 900px) { |
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 createObserver = ( | |
({ curry, pipe, evolve, merge, forEach, filter }) => { | |
const filterNodes = curry( | |
(filter, container) => { | |
let currentNode | |
const nodes = [] | |
const walker = document.createTreeWalker(container, filter) | |
while (currentNode = walker.nextNode()) nodes.push(currentNode) |
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 decoupleMethods = (Type, ...names) => names.map( | |
name => ({ [name]: (a, b) => Type.prototype[name].call(b, a) }) // could be curried | |
).reduce((acc, next) => Object.assign({}, acc, next)) | |
const { map, filter, forEach, find } = decoupleMethods( | |
Array, | |
'map', | |
'filter', | |
'forEach', | |
'find' |
NewerOlder