Skip to content

Commit

Permalink
Angular 19 fixes (#141)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
crutchcorn and autofix-ci[bot] authored Nov 25, 2024
1 parent 76f2352 commit 8bd49b5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
8 changes: 3 additions & 5 deletions packages/angular-store/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
}
},
Expand All @@ -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"
}
}
23 changes: 11 additions & 12 deletions packages/angular-store/src/index.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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()
})
Expand Down

0 comments on commit 8bd49b5

Please sign in to comment.