Created
May 9, 2020 12:35
-
-
Save barneycarroll/278cf59c2cbb14fe1ac0aa557ad373d9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {getSet, indexOf, viewOf} from './utils.js' | |
export function Mobile(){ | |
return { | |
view: v => { | |
Promise.resolve().then(reconcile) | |
return viewOf(v)(Unit) | |
} | |
} | |
const arriving = new Map | |
const removing = new Map | |
const ranges = new Map | |
const states = new Set | |
function reconcile(){ | |
if(!arriving.size) | |
return | |
const moving = new Map( | |
Array.from(arriving).filter(([key]) => | |
removing.has(key) | |
) | |
) | |
arriving.clear() | |
removing.clear() | |
} | |
function Unit({key, state}){ | |
states.add(states) | |
return { | |
view: v => | |
v.instance || m.fragment(['']), | |
onupdate: v => { | |
state.index = indexOf(v.dom) | |
}, | |
oncreate: v => { | |
state.index = indexOf(v.dom) | |
state.parent = v.dom.parentNode | |
state.range = getSet(ranges, parent, () => | |
Array(index + 1), | |
) | |
}, | |
onbeforeremove: v => { | |
removing.set(key, v) | |
return Promise.resolve() | |
}, | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment