Skip to content

Commit

Permalink
Spread widget properties in vdom (#717)
Browse files Browse the repository at this point in the history
* spread widget properties in vdom

* fix test name
  • Loading branch information
agubler committed Apr 6, 2020
1 parent 32bab69 commit 46c893e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/core/vdom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2064,7 +2064,7 @@ export function renderer(renderer: () => RenderResult): Renderer {

let rendered: RenderResult;
let invalidate: () => void;
next.properties = next.node.properties;
next.properties = { ...next.node.properties };
next.id = next.id || `${wrapperId++}`;
_idToWrapperMap.set(next.id, next);
const { id, depth, order } = next;
Expand Down Expand Up @@ -2175,7 +2175,7 @@ export function renderer(renderer: () => RenderResult): Renderer {
next.hasAnimations = hasAnimations;
next.id = id;
next.childDomWrapperId = current.childDomWrapperId;
next.properties = next.node.properties;
next.properties = { ...next.node.properties };
_wrapperSiblingMap.delete(current);
if (domNode && domNode.parentNode) {
next.domNode = domNode;
Expand Down
29 changes: 29 additions & 0 deletions tests/core/unit/vdom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3487,6 +3487,35 @@ jsdomDescribe('vdom', () => {
});
});

it('should clone properties', () => {
const factory = create().properties<{ count: number }>();
const Foo = factory(function Foo({ properties }) {
return <div>{`${properties().count}`}</div>;
});
const properties: any = { count: 0 };
const App = create({ invalidator })(function App({ middleware: { invalidator } }) {
return (
<div>
<button
onclick={() => {
invalidator();
}}
/>
{w(Foo, properties)}
</div>
);
});
const root = document.createElement('div');
const r = renderer(() => App({}));
r.mount({ domNode: root });
console.log(root.innerHTML);
assert.strictEqual(root.innerHTML, '<div><button></button><div>0</div></div>');
properties.count = 1;
(root.children[0].children[0] as any).click();
resolvers.resolveRAF();
assert.strictEqual(root.innerHTML, '<div><button></button><div>1</div></div>');
});

it('registry items', () => {
const createWidget = create();
let resolver = () => {};
Expand Down

0 comments on commit 46c893e

Please sign in to comment.