-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore!: remove store.batch, add in temporary scheduler, skip intentio…
…nally broken tests
- Loading branch information
1 parent
d751b2d
commit 6e26138
Showing
7 changed files
with
149 additions
and
95 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import type { Store } from './store' | ||
import type { Derived } from './derived' | ||
|
||
/** | ||
* What store called the current update, if any | ||
* @private | ||
*/ | ||
export const __whatStoreIsCurrentlyInUse = { | ||
current: null as Store<unknown> | null, | ||
} | ||
|
||
/** | ||
* This is here to solve the pyramid dependency problem where: | ||
* A | ||
* / \ | ||
* B C | ||
* \ / | ||
* D | ||
* | ||
* Where we deeply traverse this tree, how do we avoid D being recomputed twice; once when B is updated, once when C is. | ||
* | ||
* To solve this, we create linkedDeps that allows us to sync avoid writes to the state until all of the deps have been | ||
* resolved. | ||
* | ||
* This is a record of stores, because derived stores are not able to write values to, but stores are | ||
*/ | ||
export const __storeToDerived = new WeakMap< | ||
Store<unknown>, | ||
Set<Derived<unknown>> | ||
>() | ||
export const __derivedToStore = new WeakMap< | ||
Derived<unknown>, | ||
Set<Store<unknown>> | ||
>() | ||
|
||
export const __depsThatHaveWrittenThisTick = [] as Array< | ||
Derived<unknown> | Store<unknown> | ||
> |
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { describe, expect, test } from 'vitest' | ||
import { Derived, Store, __derivedToStore, __storeToDerived } from '../src' | ||
|
||
describe('Scheduler logic', () => { | ||
test('Should build a graph properly', () => { | ||
const count = new Store<any, any>(10) | ||
|
||
const halfCount = new Derived<any, any>({ | ||
deps: [count], | ||
fn: () => { | ||
return count.state / 2 | ||
}, | ||
}) | ||
|
||
halfCount.registerOnGraph() | ||
|
||
const doubleHalfCount = new Derived<any, any>({ | ||
deps: [halfCount], | ||
fn: () => { | ||
return halfCount.state * 2 | ||
}, | ||
}) | ||
|
||
doubleHalfCount.registerOnGraph() | ||
|
||
expect(__storeToDerived.get(count)).toContain(halfCount) | ||
expect(__derivedToStore.get(halfCount)).toContain(count) | ||
expect(__storeToDerived.get(count)).toContain(doubleHalfCount) | ||
expect(__derivedToStore.get(doubleHalfCount)).toContain(count) | ||
}) | ||
}) |
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