-
-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Derived Stores #40
base: main
Are you sure you want to change the base?
Derived Stores #40
Conversation
c0c0d1c
to
790303c
Compare
Woo! 🏎️ |
Angular is the fastest, nice 😄! |
☁️ Nx Cloud ReportCI is running/has finished running commands for commit fa65a7e. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution ✅ Successfully ran 2 targetsSent with 💌 from NxCloud. |
Out of curiosity, what's the state of this PR and what's stopping it from being reviewed/merged? |
+1 |
# Conflicts: # .eslintrc.cjs # knip.json # package.json # packages/solid-store/package.json # packages/store/package.json # packages/store/src/index.ts # packages/store/src/tests/index.test.tsx # packages/store/tests/derived.bench.ts # packages/store/tests/derived.test.ts # packages/store/tests/effect.test.ts # packages/store/tests/index.test.tsx # packages/store/tests/store.test.ts # packages/vue-store/package.json # pnpm-lock.yaml
commit: @tanstack/angular-store
@tanstack/react-store
@tanstack/solid-store
@tanstack/store
@tanstack/svelte-store
@tanstack/vue-store
|
// What store called the current update, if any | ||
_whatStoreIsCurrentlyInUse: Store<unknown> | null = null | ||
|
||
constructor(deps: Deps, fn: () => TState, options?: DerivedOptions<TState>) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would it be better if this had a flat options style like useQuery
now does?
new Derived({
storeKey: [],
storeFn: () => alert("expensive")
...options
})
I would prefer it I think
Tanner Linsley
TanStack LLC
…On Aug 17, 2024 at 9:28 AM -0600, Kevin Van Cott ***@***.***>, wrote:
@KevinVandy commented on this pull request.
In packages/store/src/derived.ts:
> +}
+
+export type Deps = Array<Derived<any> | Store<any>>
+
+export class Derived<TState> {
+ _store!: Store<TState>
+ rootStores = new Set<Store<unknown>>()
+ deps: Deps
+
+ // Functions representing the subscriptions. Call a function to cleanup
+ _subscriptions: Array<() => void> = []
+
+ // What store called the current update, if any
+ _whatStoreIsCurrentlyInUse: Store<unknown> | null = null
+
+ constructor(deps: Deps, fn: () => TState, options?: DerivedOptions<TState>) {
would it be better if this had a flat options style like useQuery now does?
new Derived({
storeKey: [],
storeFn: () => alert("expensive")
...options
})
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you commented.Message ID: ***@***.***>
|
* feat: add lazyness to derived * ci: apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
I was originally holding off as performance didn't seem up-to-snuff, but comparing it against the TS39 Polyfill, it seems that we're roughly double the speed of that, so I want to merge this in so we can start using ASAP Source of the benchmarks: https://github.com/crutchcorn/js-reactivity-benchmark/tree/tanstack |
This PR implements an initial
Derived
class implementation:This Derived implementation even solves the diamond problem:
Where writes to "a" will call "d" twice (with a flicker of incorrect data known as a "Glitch") because of the dual-derived nature. Our implementation does not have this problem and therefore can be considered "glitch-free"
This is a push-based/hot signals implementation
Benchmarks
Due to the relatively naive nature of this code (I wrote it in one night at ~midnight) there are performance implication in using this. Namely, in our benchmarks we are a far cry from Angular or Solid's implementation, but come close to Vue's implementation: