Skip to content

Commit 1727a1d

Browse files
committed
chore: add assertInInjectionContext
1 parent 2d8c66a commit 1727a1d

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed
Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
import type { Action, Dispatch, UnknownAction } from 'redux'
2-
import { ReduxProvider } from './provider'
3-
import { inject } from '@angular/core'
1+
import type { Dispatch, UnknownAction } from 'redux'
2+
import { assertInInjectionContext } from '@angular/core'
3+
import { injectStore } from './inject-store'
44

55
// TODO: Add `withTypes` support
66
export function injectDispatch<AppDispatch extends Dispatch<UnknownAction> = Dispatch<UnknownAction>>(): AppDispatch {
7-
const context = inject(ReduxProvider)
8-
// TODO: assertInInjectionContext
9-
const { store } = context
10-
7+
assertInInjectionContext(injectDispatch)
8+
const store = injectStore();
119
return store.dispatch as AppDispatch
1210
}

projects/angular-redux/src/lib/inject-selector.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { EqualityFn } from './types'
2-
import { effect, inject, Signal, signal } from '@angular/core'
2+
import { assertInInjectionContext, effect, inject, Signal, signal } from '@angular/core'
33
import { ReduxProvider } from './provider'
44

55
export interface UseSelectorOptions<Selected = unknown> {
@@ -13,6 +13,7 @@ export function injectSelector<TState = unknown, Selected = unknown>(
1313
selector: (state: TState) => Selected,
1414
equalityFnOrOptions?: EqualityFn<Selected> | UseSelectorOptions<Selected>,
1515
): Signal<Selected> {
16+
assertInInjectionContext(injectSelector)
1617
const reduxContext = inject(ReduxProvider);
1718

1819
// const { equalityFn = refEquality } =
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { inject } from "@angular/core";
1+
import { assertInInjectionContext, inject } from '@angular/core'
22
import { ReduxProvider } from './provider'
33
import type { Store, Action, UnknownAction } from 'redux'
44

55
export function injectStore<A extends Action<string> = UnknownAction, S = unknown>(): Store<S, A> {
6+
assertInInjectionContext(injectStore)
67
const context = inject(ReduxProvider)
7-
// TODO: assertInInjectionContext
88
const { store } = context
99
return store
1010
}

0 commit comments

Comments
 (0)