Skip to content

Commit a62ff0d

Browse files
committed
[optimize] update Read Me document
1 parent 45ac6ed commit a62ff0d

File tree

6 files changed

+47
-37
lines changed

6 files changed

+47
-37
lines changed

.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]

preview/Async.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { FC, PropsWithChildren } from '../source';
22

3-
const Async: FC<PropsWithChildren> = ({ children }) => (
4-
<div>Async load: {children}</div>
5-
);
6-
export default Async;
3+
const AsyncLoad: FC<PropsWithChildren> = ({ children }) => <p>Async load: {children}</p>;
4+
5+
export default AsyncLoad;

preview/Home.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { AnimateCSS, FC, lazy, observer, PropsWithChildren, WebCellProps } from
44
import { ClassClock, FunctionClock } from './Clock';
55
import { TestField } from './Field';
66

7-
const Async = lazy(() => import('./Async'));
7+
const AsyncLoad = lazy(() => import('./Async'));
88

99
const Hello: FC<WebCellProps> = ({ className, children }) => (
1010
<h1 className={className}>Hello {children}!</h1>
@@ -43,7 +43,7 @@ export const HomePage = () => (
4343
<button></button>
4444
</form>
4545

46-
<Async>content</Async>
46+
<AsyncLoad>content</AsyncLoad>
4747
<AsyncComponent>content</AsyncComponent>
4848
</>
4949
);

test/Async.spec.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ describe('Async Box component', () => {
4040
const Async = lazy(async () => ({ default: Sync }));
4141

4242
renderer.render(<Async href="test">Sync Component from Async Loading</Async>);
43+
4344
expect(document.body.innerHTML).toBe('<function-cell></function-cell>');
4445

4546
await sleep();

0 commit comments

Comments
 (0)