Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
WiP : Hot component. Must be merged with a view component or have the view supplied as an attribute at run time. View must return a static root element. The component has a redraw method which immediately rerenders the component granularly.
const= new Map()
const queue = new Set()
let scheduled = false
function schedule(){
if(scheduled) return
scheduled = true
requestAnimationFrame(() => {
for(const item of queue){
const= 密.get(item)
秘.instance = 秘.state.view.call(秘.state, 秘)
m.render(秘.dom, [秘.instance])
queue.delete(item)
}
scehduled = false
})
}
function update(vnode){
vnode.dom.vnodes = [vnode.instance]
密.set(this, vnode)
}
const HotComponent = {
oncreate: update,
onupdate: update,
onremove(vnode){
密.delete(this)
delete vnode.dom.vnodes
},
redraw(){
queue.add(this)
draw()
},
view({attrs:{view}}){
return m('div', {
style: {
display: 'contents'
}
},
view.apply(this, arguments)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment