Skip to content

Instantly share code, notes, and snippets.

Avatar
🛠️
Working on Mithril type stuff

Barney Carroll barneycarroll

🛠️
Working on Mithril type stuff
View GitHub Profile
View Presence.js
import reflow from './reflow.js'
const startEvents = ['animationstart', 'transitionrun']
const endEvents = ['animationcancel', 'animationend', 'transitioncancel', 'transitionend']
export default function Presence({attrs: {
absent,
present,
entry,
exit,
View mithril.hydrate.js
const noop = () => {}
const elementHandler = {
get: (element, key) => {
if(key === 'setAttribute')
return noop
if(key === 'style')
return {
setProperty : noop,
@barneycarroll
barneycarroll / matrix.js
Created Feb 15, 2021
Produce keyed objects from a matrix (2-dimensional array) or vice-versa
View matrix.js
export default function matrix(keys){
return subject => (
Array.isArray(subject)
?
Object.fromEntries(
keys.flatMap((key, index) =>
key == null ? [] : [[key, subject[index]]]
)
)
:
@barneycarroll
barneycarroll / split.js
Last active Feb 16, 2021
A function for splitting an array or object into several others
View split.js
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] = []
View Mobile.imperative.mjs
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 Dec 26, 2020
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.
View m.spy.mjs
// imort m from 'mithril'
export default Object.assign(
decorate(m),
m,
{
fragment: decorate(m.fragment),
},
@barneycarroll
barneycarroll / feedback.js
Last active Sep 13, 2020
A browser plugin script to identify previous / next pagination links in forums and expose them to generic keyboard navigation
View feedback.js
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({
View Islands.js
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})
View Island.js
import {indexOf} from './utils.js'
export default function Island({children: [visitor]}){
let index
let vnode
visitor({ patch, attach, render })
return {
view(){
View Mobile.js
import {getSet, indexOf, viewOf} from './utils.js'
export function Mobile(){
return {
view: v => {
Promise.resolve().then(reconcile)
return viewOf(v)(Unit)
}
}