Skip to content

Commit a9884b6

Browse files
committed
[fix] observer(FC) updating (fix EasyWebApp/DOM-Renderer#4)
1 parent 24b7c99 commit a9884b6

File tree

4 files changed

+19
-17
lines changed

4 files changed

+19
-17
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
run: pnpm i --frozen-lockfile
2525

2626
- name: Build & Publish
27-
run: npm publish --access public provenance
27+
run: npm publish --access public --provenance
2828
env:
2929
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
3030

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "web-cell",
3-
"version": "3.0.0",
3+
"version": "3.0.1",
44
"description": "Web Components engine based on VDOM, JSX, MobX & TypeScript",
55
"keywords": [
66
"web",
@@ -27,7 +27,7 @@
2727
"types": "dist/index.d.ts",
2828
"dependencies": {
2929
"@swc/helpers": "^0.5.13",
30-
"dom-renderer": "^2.4.1",
30+
"dom-renderer": "^2.4.4",
3131
"mobx": ">=6.11",
3232
"regenerator-runtime": "^0.14.1",
3333
"web-utility": "^4.4.2"

pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

source/decorator.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,23 @@ export type FunctionComponent<P extends DataObject = {}> = (props: P) => VNode;
2323
export type FC<P extends DataObject = {}> = FunctionComponent<P>;
2424

2525
function wrapFunction<P>(func: FC<P>) {
26-
return (props: P) => {
27-
const tree = func(props),
28-
renderer = new DOMRenderer();
26+
const renderer = new DOMRenderer();
2927

30-
const disposer = autorun(() => {
31-
const newTree = func(props);
28+
return (props: P) => {
29+
const tree = func(props);
30+
let disposer: IReactionDisposer | undefined;
3231

33-
if (tree.node) Object.assign(tree, renderer.patch(tree, newTree));
34-
});
3532
const { ref } = tree;
3633

3734
tree.ref = node => {
38-
if (node) tree.node = node;
39-
else disposer();
35+
disposer?.();
36+
37+
if (node)
38+
disposer = autorun(() => {
39+
const newTree = func(props);
4040

41+
renderer.patch(VNode.fromDOM(node), newTree);
42+
});
4143
ref?.(node);
4244
};
4345
return tree;

0 commit comments

Comments
 (0)