Skip to content

Commit 5d51d1c

Browse files
authored
[refactor] merge Wrap Logic of Sync & Async Function components to support Async Importing & Loading (#40)
1 parent 4b3a4f4 commit 5d51d1c

File tree

11 files changed

+1491
-1498
lines changed

11 files changed

+1491
-1498
lines changed

.npmignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
*.sh
22
.*
3-
eslint.config.mjs
4-
jest.config.ts
3+
*.config.ts
54
test/
65
preview/
76
Contributing.md

.vscode/extensions.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"esbenp.prettier-vscode",
1010
"eamodio.gitlens",
1111
"github.vscode-pull-request-github",
12-
"github.vscode-github-actions"
12+
"github.vscode-github-actions",
13+
"GitHub.copilot"
1314
]
1415
}

ReadMe.md

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,7 @@ npm install parcel @parcel/config-default @parcel/transformer-typescript-tsc -D
109109
import { DOMRenderer } from 'dom-renderer';
110110
import { FC, PropsWithChildren } from 'web-cell';
111111

112-
const Hello: FC<PropsWithChildren> = ({ children = 'World' }) => (
113-
<h1>Hello, {children}!</h1>
114-
);
112+
const Hello: FC<PropsWithChildren> = ({ children = 'World' }) => <h1>Hello, {children}!</h1>;
115113

116114
new DOMRenderer().render(<Hello>WebCell</Hello>);
117115
```
@@ -203,9 +201,7 @@ class CounterModel {
203201
const couterStore = new CounterModel();
204202

205203
const Counter: FC = observer(() => (
206-
<button onClick={() => (couterStore.times += 1)}>
207-
Counts: {couterStore.times}
208-
</button>
204+
<button onClick={() => (couterStore.times += 1)}>Counts: {couterStore.times}</button>
209205
));
210206

211207
new DOMRenderer().render(<Counter />);
@@ -419,12 +415,7 @@ class MyField extends HTMLElement implements WebField {
419415
const { name } = this;
420416

421417
return (
422-
<input
423-
name={name}
424-
onChange={({ currentTarget: { value } }) =>
425-
(this.value = value)
426-
}
427-
/>
418+
<input name={name} onChange={({ currentTarget: { value } }) => (this.value = value)} />
428419
);
429420
}
430421
}
@@ -440,6 +431,22 @@ new DOMRenderer().render(
440431

441432
### Async component
442433

434+
```tsx
435+
import { DOMRenderer } from 'dom-renderer';
436+
import { observer, PropsWithChildren } from 'web-cell';
437+
import { sleep } from 'web-utility';
438+
439+
const AsyncComponent = observer(async ({ children }: PropsWithChildren) => {
440+
await sleep(1);
441+
442+
return <p>Async Component in {children}</p>;
443+
});
444+
445+
new DOMRenderer().render(<AsyncComponent>WebCell</AsyncComponent>);
446+
```
447+
448+
### Async loading
449+
443450
#### `AsyncTag.tsx`
444451

445452
```tsx
@@ -504,10 +511,7 @@ import { DOMRenderer } from 'dom-renderer';
504511
import { AnimateCSS } from 'web-cell';
505512

506513
new DOMRenderer().render(
507-
<AnimateCSS
508-
type="fadeIn"
509-
component={props => <h1 {...props}>Fade In</h1>}
510-
/>
514+
<AnimateCSS type="fadeIn" component={props => <h1 {...props}>Fade In</h1>} />
511515
);
512516
```
513517

@@ -567,7 +571,6 @@ We recommend these libraries to use with WebCell:
567571
- **State management**: [MobX][3] (also powered by **TypeScript** & **Decorator**)
568572
- **Router**: [Cell Router][43]
569573
- **UI components**
570-
571574
- [BootCell][44] (based on **BootStrap v5**)
572575
- [MDUI][45] (based on **Material Design v3**)
573576
- [GitHub Web Widget][46]

guide/ReadMe-zh.md

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,7 @@ npm install parcel @parcel/config-default @parcel/transformer-typescript-tsc -D
109109
import { DOMRenderer } from 'dom-renderer';
110110
import { FC, PropsWithChildren } from 'web-cell';
111111

112-
const Hello: FC<PropsWithChildren> = ({ children = '世界' }) => (
113-
<h1>你好,{children}!</h1>
114-
);
112+
const Hello: FC<PropsWithChildren> = ({ children = '世界' }) => <h1>你好,{children}!</h1>;
115113

116114
new DOMRenderer().render(<Hello>WebCell</Hello>);
117115
```
@@ -203,9 +201,7 @@ class CounterModel {
203201
const couterStore = new CounterModel();
204202

205203
const Counter: FC = observer(() => (
206-
<button onClick={() => (couterStore.times += 1)}>
207-
计数:{couterStore.times}
208-
</button>
204+
<button onClick={() => (couterStore.times += 1)}>计数:{couterStore.times}</button>
209205
));
210206

211207
new DOMRenderer().render(<Counter />);
@@ -419,12 +415,7 @@ class MyField extends HTMLElement implements WebField {
419415
const { name } = this;
420416

421417
return (
422-
<input
423-
name={name}
424-
onChange={({ currentTarget: { value } }) =>
425-
(this.value = value)
426-
}
427-
/>
418+
<input name={name} onChange={({ currentTarget: { value } }) => (this.value = value)} />
428419
);
429420
}
430421
}
@@ -440,6 +431,22 @@ new DOMRenderer().render(
440431

441432
### 异步组件
442433

434+
```tsx
435+
import { DOMRenderer } from 'dom-renderer';
436+
import { observer, PropsWithChildren } from 'web-cell';
437+
import { sleep } from 'web-utility';
438+
439+
const AsyncComponent = observer(async ({ children }: PropsWithChildren) => {
440+
await sleep(1);
441+
442+
return <p>{children} 中的异步组件</p>;
443+
});
444+
445+
new DOMRenderer().render(<AsyncComponent>WebCell</AsyncComponent>);
446+
```
447+
448+
### 异步加载
449+
443450
#### `AsyncTag.tsx`
444451

445452
```tsx
@@ -564,7 +571,6 @@ https://github.com/EasyWebApp/DOM-Renderer?tab=readme-ov-file#nodejs--bun
564571
- **状态管理**[MobX][3](也由 **TypeScript****Decorator** 提供支持)
565572
- **路由**[Cell Router][43]
566573
- **UI 组件**
567-
568574
- [BootCell][44](基于 **BootStrap v5**
569575
- [MDUI][45](基于 **Material Design v3**
570576
- [GitHub Web Widget][46]

package.json

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "web-cell",
3-
"version": "3.1.0",
3+
"version": "3.2.0",
44
"description": "Web Components engine based on VDOM, JSX, MobX & TypeScript",
55
"keywords": [
66
"web",
@@ -38,41 +38,41 @@
3838
"jsdom": ">=23.1"
3939
},
4040
"devDependencies": {
41-
"@cspell/eslint-plugin": "^9.1.1",
42-
"@eslint/js": "^9.29.0",
43-
"@parcel/config-default": "~2.15.2",
44-
"@parcel/packager-ts": "~2.15.2",
45-
"@parcel/transformer-typescript-tsc": "~2.15.2",
46-
"@parcel/transformer-typescript-types": "~2.15.2",
47-
"@stylistic/eslint-plugin": "^4.4.1",
41+
"@cspell/eslint-plugin": "^9.2.0",
42+
"@eslint/js": "^9.31.0",
43+
"@parcel/config-default": "~2.15.4",
44+
"@parcel/packager-ts": "~2.15.4",
45+
"@parcel/transformer-typescript-tsc": "~2.15.4",
46+
"@parcel/transformer-typescript-types": "~2.15.4",
47+
"@stylistic/eslint-plugin": "^5.2.1",
4848
"@types/eslint-config-prettier": "^6.11.3",
4949
"@types/jest": "^29.5.14",
50-
"@types/node": "^22.15.31",
51-
"core-js": "^3.43.0",
50+
"@types/node": "^22.16.5",
51+
"core-js": "^3.44.0",
5252
"element-internals-polyfill": "^1.3.13",
53-
"eslint": "^9.29.0",
54-
"eslint-config-prettier": "^10.1.5",
53+
"eslint": "^9.31.0",
54+
"eslint-config-prettier": "^10.1.8",
5555
"eslint-plugin-react": "^7.37.5",
5656
"eslint-plugin-simple-import-sort": "^12.1.1",
57-
"globals": "^16.2.0",
57+
"globals": "^16.3.0",
5858
"husky": "^9.1.7",
5959
"jest": "^29.7.0",
6060
"jest-environment-jsdom": "^29.7.0",
6161
"jiti": "^2.4.2",
6262
"jsdom": "^26.1.0",
63-
"lint-staged": "^16.1.1",
64-
"parcel": "~2.15.2",
65-
"prettier": "^3.5.3",
66-
"prettier-plugin-sh": "^0.17.4",
63+
"lint-staged": "^16.1.2",
64+
"parcel": "~2.15.4",
65+
"prettier": "^3.6.2",
66+
"prettier-plugin-sh": "^0.18.0",
6767
"replace": "^1.2.2",
6868
"rimraf": "^6.0.1",
6969
"serve": "^14.2.4",
7070
"ts-jest": "^29.4.0",
7171
"ts-node": "^10.9.2",
72-
"typedoc": "^0.28.5",
73-
"typedoc-plugin-mdn-links": "^5.0.2",
72+
"typedoc": "^0.28.7",
73+
"typedoc-plugin-mdn-links": "^5.0.5",
7474
"typescript": "~5.8.3",
75-
"typescript-eslint": "^8.34.0"
75+
"typescript-eslint": "^8.37.0"
7676
},
7777
"pnpm": {
7878
"onlyBuiltDependencies": [
@@ -104,6 +104,7 @@
104104
"trailingComma": "none",
105105
"arrowParens": "avoid",
106106
"tabWidth": 4,
107+
"printWidth": 100,
107108
"plugins": [
108109
"prettier-plugin-sh"
109110
]

0 commit comments

Comments
 (0)