-
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.
data、store、computed可写内部字段 (_开头) 去除computed中data字段的readonlyDeep
- Loading branch information
Showing
37 changed files
with
407 additions
and
155 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"component": true | ||
} |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { load, render, sleep } from "miniprogram-simulate"; | ||
import path from "path"; | ||
export const mockFn = jest.fn(); | ||
|
||
describe("cloneData", () => { | ||
const id = load(path.resolve(__dirname, "DemoA")); // 此处必须传入绝对路径 | ||
const comp = render(id); // 渲染成自定义组件树实例 | ||
|
||
const parent = document.createElement("parent-wrapper"); // 创建挂载(父)节点 | ||
|
||
comp.attach(parent); // attach 到父亲节点上,此时会触发自定义组件的 attached 钩子 | ||
|
||
test("cloneData与data深度相等但不是一个引用值", async () => { | ||
// 1. cloneData与data不是一个引用值 | ||
expect(comp.instance.data).not.toBe(comp.instance.cloneData); | ||
|
||
// 2. cloneData与data深度相等 | ||
expect(comp.instance.data).toEqual(comp.instance.cloneData); | ||
|
||
await sleep(300); | ||
|
||
// 3. setData后,cloneData也会的值随之改变 | ||
expect(comp.instance.data.str).toBe("xxxx"); | ||
|
||
expect(comp.instance.data.obj1).toEqual({ name: "zhao", age: 20 }); | ||
|
||
// 3. cloneData与data不是一个引用值 | ||
expect(comp.instance.data).not.toBe(comp.instance.cloneData); | ||
|
||
// 4. cloneData与data深度相等 | ||
expect(comp.instance.data).toEqual(comp.instance.cloneData); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { DefineComponent, type DetailedType, RootComponent, SubComponent } from "../../src"; | ||
import type { ComponentDoc } from "../../src/api/DefineComponent/ReturnType/ComponentDoc"; | ||
import { type User, user } from "../common"; | ||
|
||
type SubA = ComponentDoc<{ | ||
properties: { | ||
aaa_str: string; | ||
aaa_num: number; | ||
aaa_user: User | null; | ||
}; | ||
}>; | ||
|
||
const subA = SubComponent<Root, SubA>()({ | ||
inherit: { | ||
aaa_str: "str", | ||
}, | ||
data: { | ||
aaa_num: 123, | ||
}, | ||
computed: { | ||
aaa_user() { | ||
return user; | ||
}, | ||
}, | ||
}); | ||
|
||
type Root = typeof rootComponent; | ||
|
||
const rootComponent = RootComponent()({ | ||
properties: { | ||
obj: Object as DetailedType<User>, | ||
}, | ||
data: { | ||
str: "string", | ||
obj1: user, | ||
}, | ||
computed: { | ||
obj2() { | ||
return user; | ||
}, | ||
}, | ||
lifetimes: { | ||
attached() { | ||
setTimeout(() => { | ||
this.setData({ | ||
str: "xxxx", | ||
obj1: { name: "zhao", age: 20 }, | ||
}); | ||
}, 200); | ||
}, | ||
}, | ||
}); | ||
|
||
DefineComponent({ | ||
name: "customeTest", | ||
rootComponent, | ||
subComponents: [subA], | ||
}); |
Empty file.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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.