Skip to content

Instantly share code, notes, and snippets.

@barneycarroll
Created May 28, 2015 10:16
Show Gist options
  • Save barneycarroll/d7e534f48f352bf2652d to your computer and use it in GitHub Desktop.
Save barneycarroll/d7e534f48f352bf2652d to your computer and use it in GitHub Desktop.
WiP: micro-config lifecycle for Mithril
import m from 'mithril'
const rendered = []
const tick = ( window.setImmediate || window.setTimeout ).bind( window, Function.prototype, 0 )
const process = () => {
const couldunmounts = []
const couldpostunmounts = []
rendered.forEach( ( [ el, { ctrl, unmount, postunmount } ] ) => {
if( unmount ) unmounts.push( [ el, ctrl, unmount ] )
if( postunmount ) unmounts.push( [ el, ctrl, postunmount ] )
} )
rendered.length = 0
tick( () => {
const ctrls = new Map()
const unmounts = []
const postunmounts = []
const mounts = []
const postmounts = []
const renders = []
const postrenders = []
rendered.forEach( ( [ el, map ] ) => {
if( ctrls.has )
} )
} )
}
m.mount( document.createElement( 'div' ), {
view : () =>
m( 'div', {
config : () =>
process
} )
} )
export default function on( node, map ){
node.attrs.config = el =>
rendered.push( el, map )
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment