-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Release-As: 1.0.5
- Loading branch information
Showing
44 changed files
with
344 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,66 @@ | ||
import type { User } from "../../jest/common"; | ||
import { DefineComponent, RootComponent, type SpecificType, SubComponent } from "../../src"; | ||
import { observable } from "mobx"; | ||
import { DefineComponent, type DetailedType, RootComponent, SubComponent } from "../../src"; | ||
import type { CompA } from "./componentA"; | ||
import type { User } from "./types"; | ||
|
||
const compA = SubComponent<RootDoc, CompA>()({ | ||
const compA = SubComponent<Root, CompA>()({ | ||
computed: { | ||
subA_user() { | ||
return this.data.user; | ||
}, | ||
}, | ||
}); | ||
|
||
type RootDoc = typeof rootComponent; | ||
// 根组件类型 | ||
type Root = typeof rootComponent; | ||
|
||
const cart = observable({ | ||
count: 1, | ||
add() { | ||
this.count++; | ||
}, | ||
}); | ||
|
||
const rootComponent = RootComponent()({ | ||
// 表示组件是否为页面,可选,默认false | ||
isPage: true, | ||
|
||
properties: { | ||
user: Object as SpecificType<User>, | ||
// 通过DetailedType明确具体类型。 | ||
user: Object as DetailedType<User>, | ||
}, | ||
data: { | ||
num: 1, | ||
}, | ||
store: { | ||
// store数据使用箭头函数写法 | ||
goodsCount: () => cart.count, | ||
}, | ||
computed: { | ||
age() { | ||
return this.data.user.age; | ||
// 计算属性字段 可对所有数据计算 | ||
goodsCountAddNum() { | ||
return this.data.goodsCount + this.data.num; | ||
}, | ||
}, | ||
// 事件和方法分离书写的 | ||
events: { | ||
onTap() { | ||
// 调用store方法,修改store数据 | ||
cart.add(); | ||
|
||
// 组件store数据自动相应 | ||
console.log(this.data.goodsCount === 2); // true | ||
}, | ||
}, | ||
watch: { | ||
goodsCountAddNum(newValue: number, oldValue: number) { | ||
console.log(newValue, oldValue); // 3 2 | ||
}, | ||
}, | ||
}); | ||
|
||
DefineComponent({ | ||
path: "/pages/index/index", | ||
path: "/pages/path", | ||
rootComponent, | ||
subComponents: [compA], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export interface User { | ||
name: string; | ||
age: number; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.