Skip to content

Instantly share code, notes, and snippets.

View barneycarroll's full-sized avatar
🛠️
Working on Mithril type stuff

Barney Carroll barneycarroll

🛠️
Working on Mithril type stuff
View GitHub Profile
import reflow from './reflow.js'
const startEvents = ['animationstart', 'transitionrun']
const endEvents = ['animationcancel', 'animationend', 'transitioncancel', 'transitionend']
export default function Presence({attrs: {
absent,
present,
entry,
exit,
const noop = () => {}
const elementHandler = {
get: (element, key) => {
if(key === 'setAttribute')
return noop
if(key === 'style')
return {
setProperty : noop,
@barneycarroll
barneycarroll / split.js
Last active February 16, 2021 15:35
A function for splitting an array or object into several others
export default function split(subject, visitor){
const isArray = Array.isArray(subject)
const container = []
void (isArray ? subject : Object.entries(subject)).forEach(function(entry){
const division = visitor.apply(this, arguments)
if(!(division in container))
container[division] = []
@barneycarroll
barneycarroll / matrix.js
Created February 15, 2021 23:13
Produce keyed objects from a matrix (2-dimensional array) or vice-versa
export default function matrix(keys){
return subject => (
Array.isArray(subject)
?
Object.fromEntries(
keys.flatMap((key, index) =>
key == null ? [] : [[key, subject[index]]]
)
)
:
import { domOf, viewOf } from './_utils.mjs'
export default function Mobile() {
const creating = new Map
const removing = new Map
return {
view: v =>
viewOf(v)(Unit),
@barneycarroll
barneycarroll / m.spy.mjs
Last active December 26, 2020 14:00
Decorates Mithril hyperscript function with a logger which assigns a persistent numeric id to nodes and logs their lifecycles. Useful for debugging Mithril rendering sequence.
// imort m from 'mithril'
export default Object.assign(
decorate(m),
m,
{
fragment: decorate(m.fragment),
},
@barneycarroll
barneycarroll / feedback.js
Last active September 13, 2020 04:22
A browser plugin script to identify previous / next pagination links in forums and expose them to generic keyboard navigation
const options = {
duration: 600,
easing: 'cubic-bezier(0, 0.55, 0.45, 1)',
fill: 'both',
}
function feedback(message = 'error'){
const $circle = render(circle)
$circle.animate({
import {viewOf, indexOf, domOf} from './utils.js'
export function EnsconcedIsland(v){
let input
let index
let dom
return {
view: v => {
viewOf(v)({render, vnode, write})
import {indexOf} from './utils.js'
export default function Island({children: [visitor]}){
let index
let vnode
visitor({ patch, attach, render })
return {
view(){
import {getSet, indexOf, viewOf} from './utils.js'
export function Mobile(){
return {
view: v => {
Promise.resolve().then(reconcile)
return viewOf(v)(Unit)
}
}