From 8bd49b552b97cbd7aeb966bb52637fb0902e9d47 Mon Sep 17 00:00:00 2001 From: Corbin Crutchley Date: Mon, 25 Nov 2024 05:03:00 -0800 Subject: [PATCH] Angular 19 fixes (#141) * fix: Angular adapter can now read updates in ngOnInit and selector's input.required reads * chore!: bump support of Angular to 19 * chore: fix publint * ci: apply automated fixes and generate docs * chore: fix eslint and tsc * ci: apply automated fixes and generate docs --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> --- packages/angular-store/package.json | 8 +++----- packages/angular-store/src/index.ts | 23 +++++++++++------------ 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/packages/angular-store/package.json b/packages/angular-store/package.json index dbb79ed..c79d764 100644 --- a/packages/angular-store/package.json +++ b/packages/angular-store/package.json @@ -6,7 +6,7 @@ "license": "MIT", "repository": { "type": "git", - "url": "https://github.com/TanStack/store.git", + "url": "git+https://github.com/TanStack/store.git", "directory": "packages/angular-store" }, "homepage": "https://tanstack.com/store", @@ -37,8 +37,6 @@ }, ".": { "types": "./dist/index.d.ts", - "esm2022": "./dist/esm2022/tanstack-angular-store.mjs", - "esm": "./dist/esm2022/tanstack-angular-store.mjs", "default": "./dist/fesm2022/tanstack-angular-store.mjs" } }, @@ -63,7 +61,7 @@ "zone.js": "^0.15.0" }, "peerDependencies": { - "@angular/common": ">=16.0.0", - "@angular/core": ">=16.0.0" + "@angular/common": ">=19.0.0", + "@angular/core": ">=19.0.0" } } diff --git a/packages/angular-store/src/index.ts b/packages/angular-store/src/index.ts index 1818e2a..f31e019 100644 --- a/packages/angular-store/src/index.ts +++ b/packages/angular-store/src/index.ts @@ -1,10 +1,10 @@ import { + DestroyRef, Injector, assertInInjectionContext, - effect, inject, + linkedSignal, runInInjectionContext, - signal, } from '@angular/core' import type { AnyUpdater, Store } from '@tanstack/store' import type { CreateSignalOptions } from '@angular/core' @@ -32,17 +32,16 @@ export function injectStore< } return runInInjectionContext(options.injector, () => { - const slice = signal(selector(store.state), options) + const destroyRef = inject(DestroyRef) + const slice = linkedSignal(() => selector(store.state), options) - effect( - (onCleanup) => { - const unsub = store.subscribe(() => { - slice.set(selector(store.state)) - }) - onCleanup(unsub) - }, - { allowSignalWrites: true }, - ) + const unsubscribe = store.subscribe(() => { + slice.set(selector(store.state)) + }) + + destroyRef.onDestroy(() => { + unsubscribe() + }) return slice.asReadonly() })