Skip to content

Commit cb56015

Browse files
committed
[fix] Mount & Update timing of Class components
[optimize] update Document links & Upstream packages
1 parent b7efb95 commit cb56015

File tree

7 files changed

+59
-57
lines changed

7 files changed

+59
-57
lines changed

Migrating.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ import {
105105
}
106106
```
107107

108-
## control Render Target with Shadow DOM Mode option
108+
## control Render Target with Shadow DOM `mode` option
109109

110110
### render to `children`
111111

@@ -144,7 +144,7 @@ import {
144144

145145
## move Shadow CSS injection into `render()`
146146

147-
This makes **Shadow CSS** to react with the data of component instances.
147+
This makes **Shadow CSS** to react with Observable Data updating.
148148

149149
```diff
150150
+import { stringifyCSS } from 'web-utility';
@@ -180,9 +180,7 @@ import {
180180
}
181181
```
182182

183-
## rename some APIs
184-
185-
[JSDoc's `@deprecated` hints][7] will lead your way to rename them:
183+
## replace some APIs
186184

187185
1. `mixin()` => `HTMLElement` & its Sub-classes
188186
2. `mixinForm()` => `HTMLElement` & `@formField`
@@ -200,4 +198,3 @@ import {
200198
[4]: https://github.com/mobxjs/mobx/blob/mobx4and5/docs/refguide/observable-decorator.md
201199
[5]: https://github.com/mobxjs/mobx/blob/mobx4and5/docs/refguide/reaction.md
202200
[6]: https://github.com/EasyWebApp/WebCell/tree/v2/MobX
203-
[7]: https://jsdoc.app/tags-deprecated.html

ReadMe-zh.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ import 'web-cell/polyfill';
494494
- [Element Internals][26]
495495
- [CSS 变量][27]
496496
- [ECMAScript 6+][28]
497-
- [TypeScript 5+][29]
497+
- [TypeScript 5+][4]
498498

499499
## 生命周期钩子
500500

@@ -524,7 +524,7 @@ import 'web-cell/polyfill';
524524
- **UI 组件**
525525

526526
- [BootCell][44](基于 **BootStrap v5**
527-
- [Material Cell][45](基于 **Material Design**
527+
- [Material Web][45](基于 **Material Design**
528528
- [GitHub Web Widget][46]
529529

530530
- **HTTP请求**[KoAJAX][47](基于 类**Koa** 中间件)
@@ -565,13 +565,12 @@ import 'web-cell/polyfill';
565565
[20]: https://facebook.github.io/jsx/
566566
[21]: https://parceljs.org/
567567
[22]: https://web-cell.dev/scaffold/
568-
[23]: https://developer.mozilla.org/en-US/docs/Web/Web_Components
569-
[24]: https://developers.google.cn/web/fundamentals/web-components/customelements
570-
[25]: https://developers.google.cn/web/fundamentals/web-components/shadowdom
571-
[26]: https://web.dev/more-capable-form-controls/
572-
[27]: https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_variables
568+
[23]: https://developer.mozilla.org/zh-CN/docs/Web/API/Web_components
569+
[24]: https://web.dev/articles/custom-elements-v1?hl=zh-cn
570+
[25]: https://web.dev/articles/shadowdom-v1?hl=zh-cn
571+
[26]: https://web.dev/articles/more-capable-form-controls?hl=zh-cn
572+
[27]: https://developer.mozilla.org/zh-CN/docs/Web/CSS/Using_CSS_custom_properties
573573
[28]: http://es6-features.org/
574-
[29]: https://www.typescriptlang.org/
575574
[30]: https://web-cell.dev/web-utility/interfaces/CustomElement.html#connectedCallback
576575
[31]: https://web-cell.dev/web-utility/interfaces/CustomElement.html#disconnectedCallback
577576
[32]: https://web-cell.dev/web-utility/interfaces/CustomElement.html#attributeChangedCallback
@@ -587,13 +586,13 @@ import 'web-cell/polyfill';
587586
[42]: https://github.com/EasyWebApp/mark-wiki
588587
[43]: https://web-cell.dev/cell-router/
589588
[44]: https://bootstrap.web-cell.dev/
590-
[45]: https://material.web-cell.dev/
589+
[45]: https://material-web.dev/
591590
[46]: https://tech-query.me/GitHub-Web-Widget/
592591
[47]: https://web-cell.dev/KoAJAX/
593592
[48]: https://web-cell.dev/web-utility/
594593
[49]: https://web-cell.dev/iterable-observer/
595594
[50]: https://github.com/EasyWebApp/Parcel-transformer-MDX
596-
[51]: https://web.dev/declarative-shadow-dom/
597-
[52]: https://reactjs.org/docs/react-api.html#reactlazy
595+
[51]: https://developer.chrome.com/docs/css-ui/declarative-shadow-dom?hl=zh-cn
596+
[52]: https://legacy.reactjs.org/docs/react-api.html#reactlazy
598597
[53]: https://github.com/EasyWebApp/WebCell/blob/main/Migrating.md
599598
[54]: https://github.com/EasyWebApp/WebCell/blob/main/Contributing.md

ReadMe.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ import 'web-cell/polyfill';
497497
- [Element Internals][26]
498498
- [CSS variables][27]
499499
- [ECMAScript 6+][28]
500-
- [TypeScript 5+][29]
500+
- [TypeScript 5+][4]
501501

502502
## Life Cycle hooks
503503

@@ -527,7 +527,7 @@ We recommend these libraries to use with WebCell:
527527
- **UI components**
528528

529529
- [BootCell][44] (based on **BootStrap v5**)
530-
- [Material Cell][45] (based on **Material Design**)
530+
- [Material Web][45] (based on **Material Design**)
531531
- [GitHub Web Widget][46]
532532

533533
- **HTTP request**: [KoAJAX][47] (based on **Koa**\-like middlewares)
@@ -568,13 +568,12 @@ We recommend these libraries to use with WebCell:
568568
[20]: https://facebook.github.io/jsx/
569569
[21]: https://parceljs.org/
570570
[22]: https://web-cell.dev/scaffold/
571-
[23]: https://developer.mozilla.org/en-US/docs/Web/Web_Components
572-
[24]: https://developers.google.cn/web/fundamentals/web-components/customelements
573-
[25]: https://developers.google.cn/web/fundamentals/web-components/shadowdom
574-
[26]: https://web.dev/more-capable-form-controls/
575-
[27]: https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_variables
571+
[23]: https://developer.mozilla.org/en-US/docs/Web/API/Web_components
572+
[24]: https://web.dev/articles/custom-elements-v1
573+
[25]: https://web.dev/articles/shadowdom-v1
574+
[26]: https://web.dev/articles/more-capable-form-controls
575+
[27]: https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties
576576
[28]: http://es6-features.org/
577-
[29]: https://www.typescriptlang.org/
578577
[30]: https://web-cell.dev/web-utility/interfaces/CustomElement.html#connectedCallback
579578
[31]: https://web-cell.dev/web-utility/interfaces/CustomElement.html#disconnectedCallback
580579
[32]: https://web-cell.dev/web-utility/interfaces/CustomElement.html#attributeChangedCallback
@@ -590,13 +589,13 @@ We recommend these libraries to use with WebCell:
590589
[42]: https://github.com/EasyWebApp/mark-wiki
591590
[43]: https://web-cell.dev/cell-router/
592591
[44]: https://bootstrap.web-cell.dev/
593-
[45]: https://material.web-cell.dev/
592+
[45]: https://material-web.dev/
594593
[46]: https://tech-query.me/GitHub-Web-Widget/
595594
[47]: https://web-cell.dev/KoAJAX/
596595
[48]: https://web-cell.dev/web-utility/
597596
[49]: https://web-cell.dev/iterable-observer/
598597
[50]: https://github.com/EasyWebApp/Parcel-transformer-MDX
599-
[51]: https://web.dev/declarative-shadow-dom/
600-
[52]: https://reactjs.org/docs/react-api.html#reactlazy
598+
[51]: https://developer.chrome.com/docs/css-ui/declarative-shadow-dom
599+
[52]: https://legacy.reactjs.org/docs/react-api.html#reactlazy
601600
[53]: https://github.com/EasyWebApp/WebCell/blob/main/Migrating.md
602601
[54]: https://github.com/EasyWebApp/WebCell/blob/main/Contributing.md

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "web-cell",
3-
"version": "3.0.0-rc.10",
3+
"version": "3.0.0-rc.15",
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.6",
30-
"dom-renderer": "^2.1.1",
30+
"dom-renderer": "^2.1.3",
3131
"mobx": ">=6.11",
3232
"regenerator-runtime": "^0.14.1",
3333
"web-utility": "^4.1.3"
@@ -64,7 +64,7 @@
6464
"rimraf": "^5.0.5",
6565
"ts-jest": "^29.1.2",
6666
"ts-node": "^10.9.2",
67-
"typedoc": "^0.25.7",
67+
"typedoc": "^0.25.8",
6868
"typedoc-plugin-mdn-links": "^3.1.15",
6969
"typescript": "~5.3.3"
7070
},

pnpm-lock.yaml

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

source/WebCell.tsx

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import {
77
stringifyDOM
88
} from 'web-utility';
99

10-
import { Defer } from './utility';
11-
1210
export interface ComponentMeta
1311
extends ElementDefinitionOptions,
1412
Partial<ShadowRootInit> {
@@ -24,7 +22,7 @@ export interface WebCell<P = {}> extends CustomElement {
2422
internals: ElementInternals;
2523
renderer: DOMRenderer;
2624
root: ParentNode;
27-
mounted: Defer;
25+
mounted: boolean;
2826
update: () => void;
2927
/**
3028
* Called at DOM tree updated
@@ -64,7 +62,7 @@ export function component(meta: ComponentMeta) {
6462
get root(): ParentNode {
6563
return this.internals.shadowRoot || this;
6664
}
67-
mounted = new Defer();
65+
mounted = false;
6866
declare mountedCallback?: () => any;
6967

7068
constructor() {
@@ -75,8 +73,6 @@ export function component(meta: ComponentMeta) {
7573
}
7674

7775
connectedCallback() {
78-
this.update();
79-
8076
const { mode } = meta;
8177
const renderChildren = !(mode != null);
8278

@@ -93,8 +89,12 @@ export function component(meta: ComponentMeta) {
9389

9490
super['connectedCallback']?.();
9591

96-
this.mounted.promise.then(this.mountedCallback);
97-
this.mounted.resolve();
92+
if (this.mounted) return;
93+
94+
this.update();
95+
96+
this.mounted = true;
97+
this.mountedCallback?.();
9898
}
9999

100100
declare render?: () => VNode;
@@ -103,11 +103,18 @@ export function component(meta: ComponentMeta) {
103103
update() {
104104
const vNode = this.render?.();
105105

106-
this.renderer.render(
107-
isEmpty(vNode) ? meta.mode ? <slot /> : <></> : vNode,
108-
this.root
106+
const content = isEmpty(vNode) ? (
107+
meta.mode ? (
108+
<slot />
109+
) : null
110+
) : (
111+
vNode
109112
);
110-
this.updatedCallback?.();
113+
114+
if (content != null) {
115+
this.renderer.render(content, this.root);
116+
this.updatedCallback?.();
117+
}
111118
}
112119

113120
disconnectedCallback() {

source/decorator.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ function wrapClass<T extends ClassComponent>(Component: T) {
7171
this['update'] = () =>
7272
this.disposers.push(autorun(() => update.call(this)));
7373

74-
Promise.resolve().then(this.boot);
74+
Promise.resolve().then(() => this.#boot());
7575
}
7676

77-
protected boot = () => {
77+
#boot() {
7878
const names: string[] =
7979
this.constructor['observedAttributes'] || [],
8080
reactions = reactionMap.get(this) || [];
@@ -88,7 +88,7 @@ function wrapClass<T extends ClassComponent>(Component: T) {
8888
)
8989
)
9090
);
91-
};
91+
}
9292

9393
disconnectedCallback() {
9494
for (const disposer of this.disposers) disposer();

0 commit comments

Comments
 (0)