Skip to content

Instantly share code, notes, and snippets.

@barneycarroll
Created May 9, 2020 12:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barneycarroll/278cf59c2cbb14fe1ac0aa557ad373d9 to your computer and use it in GitHub Desktop.
Save barneycarroll/278cf59c2cbb14fe1ac0aa557ad373d9 to your computer and use it in GitHub Desktop.
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