Skip to content

Instantly share code, notes, and snippets.

Looking for work

Barney Carroll barneycarroll

Looking for work
Block or report user

Report or block barneycarroll

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
barneycarroll / BornToDie.js
Created Apr 11, 2018
A component which redraws on post-creation & pre-removal, providing `{born, to, die,}` as flags to the supplied function
View BornToDie.js
const BornToDie = v => {
born = true,
to = false,
die = false,
let query
let draw
View Historian.js
const Historian = Object.assign(
Component => {
const histories = new WeakMap
return {
onbeforeupdate({}, old){
if(Component.onbeforeupdate && Component.onbeforeupdate.apply(this, arguments) === false)
return false
histories.set(old.state, old)
barneycarroll / broken.js
Last active Mar 10, 2018
Break a promise
View broken.js
const broken = (promise, state = {
pending: true,
settled: false,
resolved: false,
rejected: false,
value: undefined,
error: undefined,
}) => (
barneycarroll /
Created Mar 2, 2018
When a nested expression is the desired return value

Written to avoid the noisome pattern of

input => {
  const reference = expression with input


  return reference 
View mimix.js
const {assign, keys} = Object
const scope = fn =>
return fn(x => x.apply(this, arguments))
const compose = (key, values) => (
key === 'view'
barneycarroll /
Created Feb 23, 2018
Work in progress: proposal for view attributes as a core mechanism in Mithril

Precedent: render props (or, view attributes)

I've been toying the idea of 'view attributes' for a while, but over the past year they've taken off in the popular domain of React as 'render props'.

A component written to make use of view attributes is a 'view component' inasmuch as it doesn't have an opinion on downstream virtual DOM, but performs a useful function in the context of virtual DOM (whether that be transforming other attribute input, querying DOM or external references, providing state), which can be exposed via the view attribute provided to it.

Here's a sample of view components with associated demos.

The React community has already proved the far-reaching value of this concept to the point where the pattern is part of the official documentation, ahead of 'integrating with other libraries'. React Router

View NoopComponent.js
export const {
view: v => (
?, v)
barneycarroll / Blockm.js
Created Feb 22, 2018
A collection of view components for Mithril. A view component is one where the component provides no view of its own but instead accepts a view attribute which it then provides with data.
View Blockm.js
const callOBR = v =>
['tag', 'attrs']
.map(x =>
&& v[x].onbeforeremove
&& v[x], v)
View Blocker.js
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 / diffm.js
Created Feb 13, 2018
What's wrong with this?
View diffm.js
export default (component, previous = undefined) => ({
onbeforeupdate: (a, b) => (
component.onbeforeupdate(a, b) !== false
previous = b
You can’t perform that action at this time.