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 a9884b6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
run: pnpm i --frozen-lockfile

- name: Build & Publish
run: npm publish --access public provenance
run: npm publish --access public --provenance
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

Expand Down
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

1 comment on commit a9884b6

@github-actions
Copy link

Choose a reason for hiding this comment

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

Deploy preview for web-cell ready!

✅ Preview
https://web-cell-a53ja11fy-techquerys-projects.vercel.app

Built with commit a9884b6.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.