Skip to content

Commit 82adae0

Browse files
committed
add store subscribe method
1 parent 2ac2737 commit 82adae0

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

redisinsight/ui/src/utils/test-store.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createBrowserHistory } from 'history'
22

3-
import type { RootState, AppDispatch, ReduxStore } from 'uiSrc/slices/store'
3+
import type { ReduxStore } from 'uiSrc/slices/store'
44

55
// Re-export all types and exports from the real store to avoid circular dependencies during tests
66

@@ -16,7 +16,7 @@ export const setStoreRef = (store: ReduxStore) => {
1616
storeRef = store
1717
}
1818

19-
const getState = (): RootState => {
19+
const getState: ReduxStore['getState'] = () => {
2020
if (!storeRef) {
2121
throw new Error(
2222
'Store not initialized. Make sure store-dynamic is imported after store creation.',
@@ -25,7 +25,7 @@ const getState = (): RootState => {
2525
return storeRef.getState()
2626
}
2727

28-
const dispatch: AppDispatch = (action: any) => {
28+
const dispatch: ReduxStore['dispatch'] = (action: any) => {
2929
if (!storeRef) {
3030
throw new Error(
3131
'Store not initialized. Make sure store-dynamic is imported after store creation.',
@@ -34,8 +34,18 @@ const dispatch: AppDispatch = (action: any) => {
3434
return storeRef.dispatch(action)
3535
}
3636

37+
const subscribe: ReduxStore['subscribe'] = (listener: () => void) => {
38+
if (!storeRef) {
39+
throw new Error(
40+
'Store not initialized. Make sure store-dynamic is imported after store creation.',
41+
)
42+
}
43+
return storeRef.subscribe(listener)
44+
}
45+
3746
// Export store object that matches the real store interface
3847
export const store = {
3948
getState,
4049
dispatch,
50+
subscribe,
4151
}

0 commit comments

Comments
 (0)