Skip to content

Commit 9d3fa69

Browse files
committed
chore(angular): prepare pr
1 parent e9efd72 commit 9d3fa69

8 files changed

Lines changed: 54 additions & 89 deletions

File tree

.changeset/strong-lines-change.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@tanstack/angular-store': patch
3+
---
4+
5+
support input signals in angular store

docs/framework/angular/reference/functions/injectStore.md

Lines changed: 14 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -5,80 +5,39 @@ title: injectStore
55

66
# Function: injectStore()
77

8-
## Call Signature
9-
10-
```ts
11-
function injectStore<TState, TSelected>(
12-
store,
13-
selector?,
14-
options?): Signal<TSelected>;
15-
```
16-
17-
Defined in: [index.ts:16](https://github.com/TanStack/store/blob/main/packages/angular-store/src/index.ts#L16)
18-
19-
### Type Parameters
20-
21-
#### TState
22-
23-
`TState`
24-
25-
#### TSelected
26-
27-
`TSelected` = `NoInfer`\<`TState`\>
28-
29-
### Parameters
30-
31-
#### store
32-
33-
`Atom`\<`TState`\>
34-
35-
#### selector?
36-
37-
(`state`) => `TSelected`
38-
39-
#### options?
40-
41-
`CreateSignalOptions`\<`TSelected`\> & `object`
42-
43-
### Returns
44-
45-
`Signal`\<`TSelected`\>
46-
47-
## Call Signature
48-
498
```ts
509
function injectStore<TState, TSelected>(
51-
store,
52-
selector?,
53-
options?): Signal<TSelected>;
10+
storeOrStoreSignal,
11+
selector,
12+
options): Signal<TSelected>;
5413
```
5514

56-
Defined in: [index.ts:21](https://github.com/TanStack/store/blob/main/packages/angular-store/src/index.ts#L21)
15+
Defined in: [index.ts:14](https://github.com/TanStack/store/blob/main/packages/angular-store/src/index.ts#L14)
5716

58-
### Type Parameters
17+
## Type Parameters
5918

60-
#### TState
19+
### TState
6120

6221
`TState`
6322

64-
#### TSelected
23+
### TSelected
6524

6625
`TSelected` = `NoInfer`\<`TState`\>
6726

68-
### Parameters
27+
## Parameters
6928

70-
#### store
29+
### storeOrStoreSignal
7130

72-
`Atom`\<`TState`\> | `ReadonlyAtom`\<`TState`\>
31+
`Atom`\<`TState`\> | `ReadonlyAtom`\<`TState`\> | () => `Atom`\<`TState`\> \| `ReadonlyAtom`\<`TState`\>
7332

74-
#### selector?
33+
### selector
7534

7635
(`state`) => `TSelected`
7736

78-
#### options?
37+
### options
7938

80-
`CreateSignalOptions`\<`TSelected`\> & `object`
39+
`CreateSignalOptions`\<`TSelected`\> & `object` = `...`
8140

82-
### Returns
41+
## Returns
8342

8443
`Signal`\<`TSelected`\>

packages/angular-store/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
"@angular/compiler-cli": "^21.1.2",
5959
"@angular/core": "^21.1.2",
6060
"@angular/platform-browser": "^21.1.2",
61-
"@angular/platform-browser-dynamic": "^21.1.2",
6261
"ng-packagr": "^21.1.0",
6362
"zone.js": "^0.15.1"
6463
},

packages/angular-store/src/index.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@ import type { CreateSignalOptions, Signal } from '@angular/core'
1212
export * from '@tanstack/store'
1313

1414
export function injectStore<TState, TSelected = NoInfer<TState>>(
15-
storeOrStoreSignal: Atom<TState> | ReadonlyAtom<TState> | (() => Atom<TState> | ReadonlyAtom<TState>),
16-
selector: (state: NoInfer<TState>) => TSelected = (d) => d as unknown as TSelected,
15+
storeOrStoreSignal:
16+
| Atom<TState>
17+
| ReadonlyAtom<TState>
18+
| (() => Atom<TState> | ReadonlyAtom<TState>),
19+
selector: (state: NoInfer<TState>) => TSelected = (d) =>
20+
d as unknown as TSelected,
1721
options: CreateSignalOptions<TSelected> & { injector?: Injector } = {
1822
equal: shallow,
1923
},
@@ -25,20 +29,21 @@ export function injectStore<TState, TSelected = NoInfer<TState>>(
2529
}
2630

2731
return runInInjectionContext(options.injector, () => {
28-
const storeSignal = typeof storeOrStoreSignal === "function"
29-
? storeOrStoreSignal
30-
: () => storeOrStoreSignal;
32+
const storeSignal =
33+
typeof storeOrStoreSignal === 'function'
34+
? storeOrStoreSignal
35+
: () => storeOrStoreSignal
3136

32-
const slice = linkedSignal(() => selector(storeSignal().get()), options);
37+
const slice = linkedSignal(() => selector(storeSignal().get()), options)
3338

3439
effect((onCleanup) => {
3540
const { unsubscribe } = storeSignal().subscribe((s) => {
36-
slice.set(selector(s));
37-
});
38-
onCleanup(() => unsubscribe());
39-
});
41+
slice.set(selector(s))
42+
})
43+
onCleanup(() => unsubscribe())
44+
})
4045

41-
return slice.asReadonly();
46+
return slice.asReadonly()
4247
})
4348
}
4449

packages/angular-store/tests/index.test.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ import {
44
computed,
55
effect,
66
input,
7-
OnInit,
7+
inputBinding,
88
signal,
99
untracked,
10-
inputBinding,
1110
} from '@angular/core'
1211
import { TestBed } from '@angular/core/testing'
1312
import { By } from '@angular/platform-browser'
1413
import { createStore } from '@tanstack/store'
1514
import { injectStore } from '../src/index'
15+
import type { OnInit } from '@angular/core'
1616

1717
function createStableSignal<T>(fn: () => T): () => T {
1818
return computed(() => untracked(fn))
@@ -113,7 +113,10 @@ describe('injectStore', () => {
113113

114114
const storeVal = TestBed.runInInjectionContext(() => {
115115
const store = createStableSignal(() => createStore({ value: count() }))
116-
const storeVal = injectStore(() => store(), (state) => state.value)
116+
const storeVal = injectStore(
117+
() => store(),
118+
(state) => state.value,
119+
)
117120

118121
effect(() => {
119122
store().setState(() => ({ value: count() }))
@@ -140,7 +143,10 @@ describe('injectStore', () => {
140143
store = createStableSignal(() =>
141144
createStore({ doubled: this.value() * 2 }),
142145
)
143-
storeVal = injectStore(() => this.store(), (state) => state.doubled)
146+
storeVal = injectStore(
147+
() => this.store(),
148+
(state) => state.doubled,
149+
)
144150

145151
constructor() {
146152
effect(() => {
@@ -215,7 +221,10 @@ describe('injectStore', () => {
215221
store = createStableSignal(() =>
216222
createStore({ doubled: this.value() * 2 }),
217223
)
218-
storeVal = injectStore(() => this.store(), (state) => state.doubled)
224+
storeVal = injectStore(
225+
() => this.store(),
226+
(state) => state.doubled,
227+
)
219228

220229
constructor() {
221230
effect(() => {
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import '@angular/compiler';
2-
import { setupTestBed } from '@analogjs/vitest-angular/setup-testbed';
1+
import '@angular/compiler'
2+
import { setupTestBed } from '@analogjs/vitest-angular/setup-testbed'
33

4-
setupTestBed();
4+
setupTestBed()

packages/angular-store/vite.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { defineConfig } from 'vitest/config'
22
import packageJson from './package.json'
3-
import angular from '@analogjs/vite-plugin-angular';
3+
import angular from '@analogjs/vite-plugin-angular'
44

55
export default defineConfig({
66
plugins: [angular()],

pnpm-lock.yaml

Lines changed: 1 addition & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)