Skip to content

Commit 619146c

Browse files
authored
[optimize] replace Web Field mixin with Form Field decorator (#18)
1 parent 6b14dfd commit 619146c

File tree

19 files changed

+260
-287
lines changed

19 files changed

+260
-287
lines changed

.eslintrc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"@typescript-eslint/ban-ts-comment": "warn",
2626
"@typescript-eslint/ban-types": "warn",
2727
"@typescript-eslint/no-explicit-any": "warn",
28+
"@typescript-eslint/no-unsafe-declaration-merging": "off",
2829
"@typescript-eslint/no-namespace": "warn",
2930
"@typescript-eslint/no-unused-vars": "warn",
3031
"@typescript-eslint/explicit-module-boundary-types": "off"

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.parcelrc
12
.eslintrc.json
23
jest.config.ts
34
test/

.parcelrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "@parcel/config-default",
3+
"transformers": {
4+
"*.{ts,tsx}": [
5+
"@parcel/transformer-typescript-tsc"
6+
]
7+
}
8+
}

Migrating.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,9 @@ npm install mobx
6363
On the other hand, [`mobx-web-cell` adapter][6] has been merged into the core package. And cause of replacing **Prototype Overwrite** with **Class Inheritance** to refactor **Class Mixins**, `@observer` decorator should follow strict order to make observation work:
6464

6565
```diff
66+
+import { JsxProps } from 'dom-renderer';
6667
import {
67-
WebCellProps,
68+
- WebCellProps,
6869
component,
6970
attribute,
7071
- watch,
@@ -76,7 +77,8 @@ import {
7677
-import { observer } from 'mobx-web-cell';
7778
+import { observable } from 'mobx';
7879

79-
export interface MyTagProps extends WebCellProps {
80+
-export interface MyTagProps extends WebCellProps {
81+
+export interface MyTagProps extends JsxProps<HTMLElement> {
8082
count?: number
8183
}
8284

@@ -183,7 +185,7 @@ import {
183185
[JSDoc's `@deprecated` hints][7] will lead your way to rename them:
184186

185187
1. `mixin()` => `HTMLElement` & its Sub-classes
186-
2. `mixinForm()` => `WebField()`
188+
2. `mixinForm()` => `HTMLElement` & `@formField`
187189
3. `@watch` => `@observable accessor`
188190

189191
## Appendix: v3 prototype

ReadMe.md

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Demo & **GitHub template**: https://web-cell.dev/scaffold/
4545
```shell
4646
npm init -y
4747
npm install dom-renderer mobx web-cell
48-
npm install parcel @parcel/config-default "@parcel/transformer-typescript-tsc" -D
48+
npm install parcel @parcel/config-default @parcel/transformer-typescript-tsc -D
4949
```
5050

5151
#### `package.json`
@@ -102,12 +102,12 @@ npm install parcel @parcel/config-default "@parcel/transformer-typescript-tsc" -
102102

103103
`source/SubTag.tsx`
104104

105-
```jsx
106-
import { WebCellProps, component } from 'web-cell';
105+
```tsx
106+
import { component, FC, PropsWithChildren } from 'web-cell';
107107

108-
export function InlineTag({ children }: WebCellProps) {
109-
return <span>{children}</span>;
110-
}
108+
export const InlineTag: FC<PropsWithChildren> = ({ children }) => (
109+
<span>{children}</span>
110+
);
111111

112112
@component({
113113
tagName: 'sub-tag'
@@ -124,12 +124,14 @@ export class SubTag extends HTMLElement {
124124
`source/TestTag.tsx`
125125

126126
```tsx
127-
import { WebCellProps, component, attribute, observer, on } from 'web-cell';
127+
import { JsxProps } from 'dom-renderer';
128128
import { observable } from 'mobx';
129+
import { component, attribute, observer, on } from 'web-cell';
130+
import { stringifyCSS } from 'web-utility';
129131

130132
import { SubTag } from './SubTag';
131133

132-
export interface TestTagProps extends WebCellProps {
134+
export interface TestTagProps extends JsxProps<HTMLElement> {
133135
topic?: string;
134136
}
135137

@@ -152,6 +154,15 @@ export class TestTag extends HTMLElement {
152154

153155
state = new State();
154156

157+
style = stringifyCSS({
158+
'.topic': {
159+
color: 'lightblue'
160+
},
161+
'.topic.active': {
162+
color: 'lightpink'
163+
}
164+
});
165+
155166
onClick = () => (this.topic = 'Example');
156167

157168
@on('click', ':host h1')
@@ -160,21 +171,12 @@ export class TestTag extends HTMLElement {
160171
}
161172

162173
render() {
163-
const { topic } = this,
174+
const { style, topic } = this,
164175
{ status } = this.state;
165176

166177
return (
167178
<>
168-
<style>
169-
{stringifyCSS({
170-
'.topic': {
171-
color: 'lightblue'
172-
},
173-
'.topic.active': {
174-
color: 'lightpink'
175-
}
176-
})}
177-
</style>
179+
<style>{style}</style>
178180

179181
<h1 title={topic} className={`topic ${status}`}>
180182
{topic}

legacy/utility/index.ts

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

legacy/utility/vDOM.ts

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

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "web-cell",
3-
"version": "3.0.0-rc.2",
3+
"version": "3.0.0-rc.4",
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.2",
30+
"dom-renderer": "^2.0.4",
3131
"mobx": ">=6.11",
3232
"regenerator-runtime": "^0.14.1",
3333
"web-utility": "^4.1.3"
@@ -45,16 +45,16 @@
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.17.0",
49-
"@typescript-eslint/parser": "^6.17.0",
48+
"@typescript-eslint/eslint-plugin": "^6.18.0",
49+
"@typescript-eslint/parser": "^6.18.0",
5050
"core-js": "^3.35.0",
5151
"element-internals-polyfill": "^1.3.10",
5252
"eslint": "^8.56.0",
5353
"eslint-config-prettier": "^9.1.0",
5454
"husky": "^8.0.3",
5555
"jest": "^29.7.0",
5656
"jest-environment-jsdom": "^29.7.0",
57-
"jsdom": "^23.1.0",
57+
"jsdom": "^23.2.0",
5858
"lint-staged": "^15.2.0",
5959
"open-cli": "^8.0.0",
6060
"parcel": "~2.11.0",
@@ -63,7 +63,7 @@
6363
"ts-jest": "^29.1.1",
6464
"ts-node": "^10.9.2",
6565
"typedoc": "^0.25.6",
66-
"typedoc-plugin-mdn-links": "^3.1.10",
66+
"typedoc-plugin-mdn-links": "^3.1.11",
6767
"typescript": "~5.3.3"
6868
},
6969
"scripts": {

0 commit comments

Comments
 (0)