-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3a995af
commit 17fd0b2
Showing
12 changed files
with
199 additions
and
82 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { test,expect, describe, beforeAll } from "vitest" | ||
import { createStore,ComputedScopeRef,computed, IStore } from ".." | ||
|
||
|
||
const Account = { | ||
order:{ | ||
price:2, | ||
count:3, | ||
total:computed((scope)=>{ | ||
return scope.price * scope.count | ||
},{ | ||
id:"total", | ||
}) | ||
} | ||
} | ||
|
||
|
||
describe("基本同步计算",()=>{ | ||
|
||
test("默认同步计算",async ()=>{ | ||
const store = createStore({ | ||
price:2, | ||
count:3, | ||
total:computed((scope)=>{ | ||
return scope.price * scope.count | ||
}) | ||
}) | ||
store.setState((draft)=>draft.count = 4) | ||
expect(store.state.total).toBe(8) | ||
}) | ||
}) | ||
|
||
describe("Scope指向",()=>{ | ||
|
||
test("默认Scope指向Current=order",()=>{ | ||
return new Promise<void>((resolve)=>{ | ||
const store = createStore({ | ||
order:{ | ||
price:2, | ||
count:3, | ||
total:computed((scope)=>{ | ||
expect(scope.price).toBe(2) | ||
expect(scope.count).toBe(3) | ||
resolve() | ||
}) | ||
} | ||
}) | ||
store.state.order.total // 读取操作时创建计算属性 | ||
}) | ||
|
||
}) | ||
test("Scope指向Root",()=>{ | ||
return new Promise<void>((resolve)=>{ | ||
const store = createStore({ | ||
order:{ | ||
price:2, | ||
count:3, | ||
total:computed<number>((scope)=>{ | ||
expect(scope.order.price).toBe(2) | ||
expect(scope.order.count).toBe(3) | ||
resolve() | ||
return scope.order.price * scope.order.count | ||
}) | ||
} | ||
},{ | ||
computedScope:()=>ComputedScopeRef.Root | ||
}) | ||
|
||
store.state.order.total // 读取操作时创建计算属性 | ||
}) | ||
}) | ||
}) |
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.