Skip to content

Commit 01be249

Browse files
authored
[add] Quick Start document of WebCell v3 (#19)
1 parent 619146c commit 01be249

File tree

12 files changed

+542
-211
lines changed

12 files changed

+542
-211
lines changed

ReadMe.md

Lines changed: 439 additions & 138 deletions
Large diffs are not rendered by default.

legacy/utility/MobX.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "web-cell",
3-
"version": "3.0.0-rc.4",
3+
"version": "3.0.0-rc.5",
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.3",
30-
"dom-renderer": "^2.0.4",
30+
"dom-renderer": "^2.0.5",
3131
"mobx": ">=6.11",
3232
"regenerator-runtime": "^0.14.1",
3333
"web-utility": "^4.1.3"
@@ -45,8 +45,8 @@
4545
"@parcel/transformer-typescript-tsc": "~2.11.0",
4646
"@parcel/transformer-typescript-types": "~2.11.0",
4747
"@types/jest": "^29.5.11",
48-
"@typescript-eslint/eslint-plugin": "^6.18.0",
49-
"@typescript-eslint/parser": "^6.18.0",
48+
"@typescript-eslint/eslint-plugin": "^6.18.1",
49+
"@typescript-eslint/parser": "^6.18.1",
5050
"core-js": "^3.35.0",
5151
"element-internals-polyfill": "^1.3.10",
5252
"eslint": "^8.56.0",
@@ -62,7 +62,7 @@
6262
"rimraf": "^5.0.5",
6363
"ts-jest": "^29.1.1",
6464
"ts-node": "^10.9.2",
65-
"typedoc": "^0.25.6",
65+
"typedoc": "^0.25.7",
6666
"typedoc-plugin-mdn-links": "^3.1.11",
6767
"typescript": "~5.3.3"
6868
},

pnpm-lock.yaml

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

preview/Async.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { FC, PropsWithChildren } from '../source';
2+
3+
const Async: FC<PropsWithChildren> = ({ children }) => (
4+
<div>Async load: {children}</div>
5+
);
6+
export default Async;

preview/Home.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { formToJSON } from 'web-utility';
2-
import { FC, PropsWithChildren } from '../source';
2+
import { FC, PropsWithChildren, lazy } from '../source';
33

44
import { ClassClock, FunctionClock } from './Clock';
55
import { TestField } from './Field';
66

7+
const Async = lazy(() => import('./Async'));
8+
79
const Hello: FC<PropsWithChildren> = ({ children }) => (
810
<h1>Hello {children}!</h1>
911
);
@@ -23,6 +25,7 @@ export const HomePage = () => (
2325
</a>
2426
.
2527
</div>
28+
2629
<ul>
2730
<li>
2831
<FunctionClock />
@@ -31,6 +34,7 @@ export const HomePage = () => (
3134
<ClassClock />
3235
</li>
3336
</ul>
37+
3438
<form
3539
// @ts-ignore
3640
onSubmit={({ currentTarget }) =>
@@ -41,5 +45,7 @@ export const HomePage = () => (
4145

4246
<button></button>
4347
</form>
48+
49+
<Async>content</Async>
4450
</>
4551
);

preview/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"compilerOptions": {
33
"target": "ES6",
4+
"module": "ES2020",
45
"moduleResolution": "Node",
56
"useDefineForClassFields": true,
67
"jsx": "react-jsx",

source/Async.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
import { observable } from 'mobx';
2-
import { HTMLProps } from 'web-utility';
2+
import { JsxProps } from 'dom-renderer';
33

44
import { ClassComponent, WebCell, component } from './WebCell';
55
import {
6+
FC,
67
FunctionComponent,
8+
PropsWithChildren,
79
WebCellComponent,
810
observer,
911
reaction
1012
} from './decorator';
1113

1214
export type ComponentTag = string | WebCellComponent;
1315

14-
export type WebCellProps<T extends HTMLElement = HTMLElement> = HTMLProps<T>;
16+
export type WebCellProps<T extends HTMLElement = HTMLElement> = JsxProps<T>;
1517

1618
export interface AsyncBoxProps extends WebCellProps {
1719
loader: () => Promise<ComponentTag>;
@@ -31,7 +33,7 @@ export class AsyncBox extends HTMLElement {
3133
accessor loader: AsyncBoxProps['loader'];
3234

3335
@observable
34-
accessor component: ComponentTag;
36+
accessor component: FC<PropsWithChildren>;
3537

3638
@observable
3739
accessor delegatedProps: AsyncBoxProps['delegatedProps'];
@@ -43,8 +45,12 @@ export class AsyncBox extends HTMLElement {
4345
@reaction((element: AsyncBox) => element.loader)
4446
protected async load() {
4547
this.component = undefined;
46-
this.component = await this.loader();
4748

49+
const Tag = await this.loader();
50+
51+
this.component = ({ children, ...props }) => (
52+
<Tag {...props}>{children}</Tag>
53+
);
4854
this.emit('load', this.component);
4955
}
5056

source/MobX.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { DataObject } from 'dom-renderer';
2+
import { ObservableValue } from 'mobx/dist/internal';
3+
4+
export function getMobxData<T extends DataObject>(observable: T) {
5+
for (const key of Object.getOwnPropertySymbols(observable)) {
6+
const store = observable[key as keyof T]?.values_ as Map<
7+
string,
8+
ObservableValue<T>
9+
>;
10+
if (store instanceof Map)
11+
return Object.fromEntries(
12+
Array.from(store, ([key, { value_ }]) => [key, value_])
13+
) as T;
14+
}
15+
}

0 commit comments

Comments
 (0)