Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 4 additions & 2 deletions packages/f-engine/src/canvas/render/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,16 @@ function createElement(parent: VNode, element: JSX.Element): VNode | VNode[] | n
function destroyElement(vNode: VNode | VNode[] | null) {
Children.map(vNode, (node: VNode | null) => {
if (!node) return;
const { component, children } = node;
const { component, children, shape, tag } = node;
if (component) {
component.willUnmount();
destroyElement(children);
component.didUnmount();
component.destroy();
} else {
} else if (children) {
destroyElement(children);
} else if (tag === Shape && shape) {
shape.destroy();
}
});
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions packages/f-engine/test/canvas/render/vnodeUpdate.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,41 @@ describe('vnode 更新', () => {

expect(ref.current._vNode.props.update).toBe(true);
});
it('基础图形更新', async () => {
const context = createContext();
const { props } = (
<Canvas context={context}>
<rect
style={{
width: 36,
height: 36,
fill: 'red',
}}
/>
</Canvas>
);

const canvas = new Canvas(props);
await canvas.render();

const { props: nextProps } = (
<Canvas context={context}>
<circle
style={{
cx: 80,
cy: 30,
r: 20,
lineWidth: 2,
stroke: '#e45649',
fill: 'blue',
}}
/>
</Canvas>
);
await delay(500);
await canvas.update(nextProps);

await delay(200);
expect(context).toMatchImageSnapshot();
});
});
Loading