Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spread widget properties in vdom #717

Merged
merged 2 commits into from
Apr 6, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 close properties', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clone?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated, thanks :D

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