@e7w/easy-model 0.1.6 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -388,11 +388,13 @@ class UserModel {
|
|
|
388
388
|
}
|
|
389
389
|
}
|
|
390
390
|
|
|
391
|
+
const User = provide(UserModel);
|
|
392
|
+
|
|
391
393
|
class TeamModel {
|
|
392
394
|
members: UserModel[] = [];
|
|
393
395
|
|
|
394
396
|
addMember(userId: string) {
|
|
395
|
-
const user =
|
|
397
|
+
const user = User(userId);
|
|
396
398
|
this.members.push(user);
|
|
397
399
|
}
|
|
398
400
|
|
|
@@ -408,14 +410,14 @@ function TeamManagement() {
|
|
|
408
410
|
<div>
|
|
409
411
|
<h2>团队成员</h2>
|
|
410
412
|
{team.members.map(member => (
|
|
411
|
-
<UserCard key={member.id}
|
|
413
|
+
<UserCard key={member.id} id={member.id} />
|
|
412
414
|
))}
|
|
413
415
|
</div>
|
|
414
416
|
);
|
|
415
417
|
}
|
|
416
418
|
|
|
417
|
-
function UserCard({
|
|
418
|
-
const observedUser =
|
|
419
|
+
function UserCard({ id }: { id: UserModel["id"] }) {
|
|
420
|
+
const observedUser = useModel(User, [id]);
|
|
419
421
|
|
|
420
422
|
return (
|
|
421
423
|
<div>
|
|
@@ -432,16 +434,12 @@ function UserCard({ user }: { user: UserModel }) {
|
|
|
432
434
|
function App() {
|
|
433
435
|
return (
|
|
434
436
|
<div>
|
|
435
|
-
{/* 开发环境配置 */}
|
|
436
437
|
<Container namespace="dev">
|
|
437
438
|
<VInjection schema={configSchema} val={devConfig} />
|
|
438
|
-
<DevTools />
|
|
439
439
|
</Container>
|
|
440
440
|
|
|
441
|
-
{/* 生产环境配置 */}
|
|
442
441
|
<Container namespace="prod">
|
|
443
442
|
<VInjection schema={configSchema} val={prodConfig} />
|
|
444
|
-
<MainApp />
|
|
445
443
|
</Container>
|
|
446
444
|
</div>
|
|
447
445
|
);
|
|
@@ -453,7 +451,6 @@ function App() {
|
|
|
453
451
|
### 1. 模型设计
|
|
454
452
|
|
|
455
453
|
- **单一职责**: 每个模型类应该只负责一个特定的业务领域
|
|
456
|
-
- **不可变更新**: 尽量使用不可变的方式更新状态
|
|
457
454
|
- **类型安全**: 充分利用 TypeScript 的类型系统
|
|
458
455
|
|
|
459
456
|
```tsx
|