Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
export const h=(t,p,...c)=>({t,p,c,k:p&&p.key})
export const render=(e,d,t=d.t||(d.t={}),p,r,c)=>
// arrays
e.pop?e.map((e,p)=>render(e,d,t.o&&t.o[p])):
// components
e.t.call?(e.i=render((render.c=e).t({children:e.c,...e.p},e.s=t.s||{},t=>
render(Object.assign(e.s,t)&&e,d,e)),t.i||d,t&&t.i||{}),e):(
// create notes
e.d=t.d||(e.t?document.createElement(e.t):new Text(e.p)),
// diff props
e.p!=t.p&&(e.t?Object.keys(e.p||{}).map(d=>
(c=e.p[d])!=(t.p&&t.p[d])&&(d in e.d?e.d[d]=c:e.d.setAttribute(d,c))):e.d.data=e.p),
// insert at position
t.d&&p==r||d.insertBefore(e.d,d.childNodes[p+1]),
// diff children (typed/keyed)
e.o=e.c.concat.apply([],e.c).map((d,p)=>render(d=d.c?d:h('',d),e.d,
t.o&&t.o.find((e,c)=>e&&e.t==d.t&&e.k==d.k&&(c==p&&(p=r),t.o[c]=0,e))||{},p)),
// remove stragglers
t.o&&t.o.map(e=>e&&e.d.remove()),Object.assign(t,e)
)
h=(t,p,...c)=>({t,p,c,k:p&&p.key}),render=(e,d,t=d.t||(d.t={}),p,r,c)=>e.pop?e.map((e,p)=>render(e,d,t.o&&t.o[p])):e.t.call?(e.i=render((render.c=e).t({children:e.c,...e.p},e.s=t.s||{},t=>render(Object.assign(e.s,t)&&e,d,e)),t.i||d,t&&t.i||{}),e):(e.d=t.d||(e.t?document.createElement(e.t):new Text(e.p)),e.p!=t.p&&(e.t?Object.keys(e.p||{}).map(d=>(c=e.p[d])!=(t.p&&t.p[d])&&(d in e.d?e.d[d]=c:e.d.setAttribute(d,c))):e.d.data=e.p),t.d&&p==r||d.insertBefore(e.d,d.childNodes[p+1]),e.o=e.c.concat.apply([],e.c).map((d,p)=>render(d=d.c?d:h("",d),e.d,t.o&&t.o.find((e,c)=>e&&e.t==d.t&&e.k==d.k&&(c==p&&(p=r),t.o[c]=0,e))||{},p)),t.o&&t.o.map(e=>e&&e.d.remove()),Object.assign(t,e));
little={h,render};typeof module!='undefined'&&(module.exports=little)
{"name":"little-vdom","module":"little-vdom.js","main":"little-vdom.min.js","version":"0.1.0"}
@jimfranke

This comment has been minimized.

Copy link

jimfranke commented Mar 8, 2020

Can you please check why returning an array (fragment) as the root from a component doesnt work? Thanks

@iosio

This comment has been minimized.

Copy link

iosio commented Mar 17, 2020

@jimfranke
No fragments here either, but here's a spin on this using display:contents as a fragment and a few other bug fixes and add-ons. Not tweet size, no SVG but works pretty well. https://gist.github.com/iosio/8e76d782570b51ddbca64809d0bf1669

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.