Skip to content

Commit 957e324

Browse files
redux rootState implemented
1 parent 0edadcb commit 957e324

File tree

7 files changed

+616
-35
lines changed

7 files changed

+616
-35
lines changed

admin-ui/app/redux/hooks.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Redux Typed Hooks with store-inferred types
2+
// Usage: import { useAppDispatch, useAppSelector } from '@/redux/hooks'
3+
4+
import { TypedUseSelectorHook, useDispatch, useSelector } from 'react-redux'
5+
import type { RootState } from './types'
6+
import store from './store'
7+
8+
// Store-inferred dispatch type
9+
export type AppDispatch = typeof store.dispatch
10+
export type AppStore = typeof store
11+
12+
// Typed hooks
13+
export const useAppDispatch = () => useDispatch<AppDispatch>()
14+
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector
15+
16+
export type { RootState }

admin-ui/app/redux/reducers/ReducerRegistry.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,41 @@
1+
// Reducer Registry - manages dynamic reducer registration for plugins
2+
3+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
4+
type AnyReducer = (state: any, action: any) => any
5+
type ReducerMap = { [key: string]: AnyReducer }
6+
type ChangeListener = (reducers: ReducerMap) => void
7+
18
class ReducerRegistry {
2-
private _emitChange: ((reducers: { [key: string]: any }) => void) | null
3-
private _reducers: { [key: string]: any }
9+
private _emitChange: ChangeListener | null
10+
private _reducers: ReducerMap
411

512
constructor() {
613
this._emitChange = null
714
this._reducers = {}
815
}
916

10-
getReducers(): { [key: string]: any } {
17+
getReducers(): ReducerMap {
1118
return { ...this._reducers }
1219
}
1320

14-
register(name: string, reducer: any): void {
21+
register(name: string, reducer: AnyReducer): void {
1522
this._reducers = { ...this._reducers, [name]: reducer }
1623
if (this._emitChange) {
1724
this._emitChange(this.getReducers())
1825
}
1926
}
2027

21-
setChangeListener(listener: (reducers: { [key: string]: any }) => void): void {
28+
setChangeListener(listener: ChangeListener): void {
2229
this._emitChange = listener
2330
}
31+
32+
hasReducer(name: string): boolean {
33+
return name in this._reducers
34+
}
35+
36+
getReducer(name: string): AnyReducer | undefined {
37+
return this._reducers[name]
38+
}
2439
}
2540

2641
const reducerRegistry = new ReducerRegistry()

0 commit comments

Comments
 (0)