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
const findOBR = v => {
while(v.length || !(v.tag.onbeforeremove || v.attrs && v.attrs.onbeforeremove))
v = v.instance || v.children || v[0]
return v
}
const persist = v => {
const target = findOBR(v.instance || v.children)
@barneycarroll
barneycarroll / diffm.js
Created February 13, 2018 12:21
What's wrong with this?
export default (component, previous = undefined) => ({
...component,
onbeforeupdate: (a, b) => (
component.onbeforeupdate
&&
component.onbeforeupdate(a, b) !== false
&&
previous = b
),
@barneycarroll
barneycarroll / domicile.js
Created January 31, 2018 17:17
WiP: mechanism for persisting DOM across the tree in Mithril
import m from 'mithril'
const find = predicate => generator => {
for(const item of generator)
if(predicate(item))
return item
}
const horizontalElementQuery = function * (root = document){
const backlog = []
@barneycarroll
barneycarroll / pave.js
Last active January 30, 2018 17:34
Find the path to a given vnode inside another vnode eg pave(document.body.vnodes, vnode)
const pave = (container, target, path = []) => (
container === target
?
path
:
Array.isArray(container)
?
container.filter((a, i) => pave(a, target, [...path, i])).pop()
:
container.instance
@barneycarroll
barneycarroll / overloaded-patchinko.js
Last active January 22, 2018 18:16
Patchinko's overloaded module re-written in terse yet spacious expressions (source: https://github.com/barneycarroll/patchinko/blob/master/overloaded.js)
export default function O(a){
return (
arguments.length == 1
?
typeof a != 'function'
?
new O(a => O(b, a))
:
this instanceof O
?
@barneycarroll
barneycarroll / m.inline-refs.js
Created January 22, 2018 15:05
Inline node reference assignment in Mithril
const login = {
view : ({state}) =>
m('form#login', {
onsubmit: e => {
e.preventDefault()
console.log(
state.email.dom.value,
state.pass.dom.value,
)
@barneycarroll
barneycarroll / thinkpol.js
Created January 16, 2018 15:00
I'm afraaaid that that is the nature of the Hard Left
export const censored = $ =>
$ == undefined || $ === false ? '' : $
export const censor = ({ censored, strings, expressions }) =>
strings.reduce((a, c, i, [], b = expressions[i - 1]) =>
a + censored(b) ? '' : b + c
)
export default (strings, ...expressions) =>
Array.isArray(strings)
@barneycarroll
barneycarroll / README.md
Last active January 12, 2018 15:06
Key => value, a function for quickly declaring a bunch of things from desctructuring assignments

Usage:

import kv from 'kv'

const {
  SOME,
  CONSTANTS,
  FOR_INTERNAL_USE,
} = kv(Symbol)
import on from 'on.js'

async function royalAirForce(){
  await on(requestAnimationFrame)

  renderX()
  
  await on(requestAnimationFrame)
// You can't proxy function application onto objects :/
import {O} from 'patchinko'
const Patchem = def =>
O({}, def, [{}, 'oninit', 'onbeforeupdate'].reduce((patch, key) =>
O(patch, {
[key](node){
O(node, {
state : new Proxy(v.state, {