all repos — h3 @ f3b732549571e6b600b730d698f9857397719e55

A tiny, extremely minimalist JavaScript microframework.

Fixed incorrect property deletion.
h3rald h3rald@h3rald.com
Sat, 26 Sep 2020 15:21:00 +0200
commit

f3b732549571e6b600b730d698f9857397719e55

parent

2429434e95b3d23fb6c2f21645534fb9d796a85a

2 files changed, 11 insertions(+), 2 deletions(-)

jump to
M __tests__/vnode.js__tests__/vnode.js

@@ -77,6 +77,16 @@ vnode1.redraw({ node, vnode });

expect(node.checked).toEqual(false); }); + it("should handle falsy props when redrawing", () => { + const vnode1 = h("test-element", { q: 1}); + const node = vnode1.render(); + expect(node.q).toEqual(1); + const vnode = h("test-element", { q: 0}); + vnode1.redraw({ node, vnode }); + expect(node.q).toEqual(0); + expect(vnode1.props.q).toEqual(0); + }); + it("should handle non-string props as properties and not create attributes", () => { const v = h("div", { test: true,
M h3.jsh3.js

@@ -393,11 +393,10 @@ oldvnode.props[a] = newvnode.props[a];

newvnode.props[a] ? node.setAttribute(a, "") : node.removeAttribute(a); - } else if (!newvnode.props[a]) { + } else if ([null, undefined].includes(newvnode.props[a])) { delete oldvnode.props[a]; node.removeAttribute(a); } else if ( - newvnode.props[a] && newvnode.props[a] !== oldvnode.props[a] ) { oldvnode.props[a] = newvnode.props[a];