Skip to content

Commit

Permalink
[fix] observer(FC) updating (fix EasyWebApp/DOM-Renderer#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
TechQuery committed Nov 9, 2024
1 parent 24b7c99 commit 76516b8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 1,6 @@
{
"name": "web-cell",
"version": "3.0.0",
"version": "3.0.1",
"description": "Web Components engine based on VDOM, JSX, MobX & TypeScript",
"keywords": [
"web",
Expand All @@ -27,7 27,7 @@
"types": "dist/index.d.ts",
"dependencies": {
"@swc/helpers": "^0.5.13",
"dom-renderer": "^2.4.1",
"dom-renderer": "^2.4.4",
"mobx": ">=6.11",
"regenerator-runtime": "^0.14.1",
"web-utility": "^4.4.2"
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 11 additions & 9 deletions source/decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 23,23 @@ export type FunctionComponent<P extends DataObject = {}> = (props: P) => VNode;
export type FC<P extends DataObject = {}> = FunctionComponent<P>;

function wrapFunction<P>(func: FC<P>) {
return (props: P) => {
const tree = func(props),
renderer = new DOMRenderer();
const renderer = new DOMRenderer();

const disposer = autorun(() => {
const newTree = func(props);
return (props: P) => {
const tree = func(props);
let disposer: IReactionDisposer | undefined;

if (tree.node) Object.assign(tree, renderer.patch(tree, newTree));
});
const { ref } = tree;

tree.ref = node => {
if (node) tree.node = node;
else disposer();
disposer?.();

if (node)
disposer = autorun(() => {
const newTree = func(props);

renderer.patch(VNode.fromDOM(node), newTree);
});
ref?.(node);
};
return tree;
Expand Down

0 comments on commit 76516b8

Please sign in to comment.