Skip to content

Commit fb69e91

Browse files
committed
feat(error): 不能定义setData 为key
1 parent 4b86f7c commit fb69e91

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

src/computed.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ export class Computed<C extends { [K: string]: () => any } = any> {
5858
};
5959

6060
constructor(context: Context, public computed: C) {
61+
if ("setData" in computed) {
62+
throw new Error(`can not be used [setData] as key`);
63+
}
6164
for (const key in computed) {
6265
if (key in context.data.state) {
6366
throw new Error(`"data" and "computed" has the same key:[${key}]`);

src/data.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ export class Data<D = any> {
1717
};
1818

1919
constructor(context: Context, public data: D) {
20+
if ("setData" in data) {
21+
throw new Error(`can not be used [setData] as key`);
22+
}
2023
for (const key in data) {
2124
this.state[key] = new DataState(data[key]);
2225
}

src/methods.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ export class Methods<M extends { [K: string]: (...args: any[]) => any } = any> {
2020
func = {} as { [K: string]: (...args: any[]) => any };
2121

2222
constructor(private context: Context, public methods: M) {
23+
if ("setData" in methods) {
24+
throw new Error(`can not be used [setData] as key`);
25+
}
2326
for (const key in methods) {
2427
if (key in context.data.state || key in context.computed.state) {
2528
throw new Error(

0 commit comments

Comments
 (0)