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,m,y)=>
// arrays
e.map?e.map((e,p)=>render(e,d,t.o&&t.o[p])):
// components
e.t.call?(e.i=render((render.c=e).t(Object.assign({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||{}),d.t=t=e):(
// create notes
m=t.d||(e.t?document.createElement(e.t):new Text(e.p)),
// diff props
(e.t?Object.keys(Object.assign({},t.p,e.p)).map(d=>
(c=e.p&&e.p[d])!=(t.p&&t.p[d])&&(d in m?(m[d]=c):m[(c?'set':'remove')+'Attribute'](d, c))):m.data=e.p),
// copy children for storage
y=(t.o||[]).slice(),
// diff children (typed/keyed)
e.o=e.c.concat.apply([],e.c).map((d,p)=>render(d=d&&d.c?d:h('',d),m,
y.find((e,c)=>e&&e.t==d.t&&e.k==d.k&&(c==p&&(p=r),y[c]=0,e))||{},p)),
// insert at position
t.d&&p==r||d.insertBefore(e.d=m,d.childNodes[p+1]),
// remove stragglers
y.map(e=>(y=e.i&&e.i.d||e.d)&&y.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,m,y)=>e.map?e.map((e,p)=>render(e,d,t.o&&t.o[p])):e.t.call?(e.i=render((render.c=e).t(Object.assign({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||{}),d.t=t=e):(m=t.d||(e.t?document.createElement(e.t):new Text(e.p)),e.t?Object.keys(Object.assign({},t.p,e.p)).map(d=>(c=e.p&&e.p[d])!=(t.p&&t.p[d])&&(d in m?m[d]=c:m[(c?'set':'remove')+'Attribute'](d,c))):m.data=e.p,y=(t.o||[]).slice(),e.o=e.c.concat.apply([],e.c).map((d,p)=>render(d=d&&d.c?d:h('',d),m,y.find((e,c)=>e&&e.t==d.t&&e.k==d.k&&(c==p&&(p=r),y[c]=0,e))||{},p)),t.d&&p==r||d.insertBefore(e.d=m,d.childNodes[p+1]),y.map(e=>(y=e.i&&e.i.d||e.d)&&y.remove()),Object.assign(t,e))
little={h,render};typeof module<'u'&&(module.exports=little)
{"name":"little-vdom","module":"little-vdom.js","main":"little-vdom.min.js","version":"0.2.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.