import type { Action, Store } from './store';
type ActionCreator
= (payload: P) => Action;
interface BridgeStore {
store: Store;
actions: { [key: string]: ActionCreator };
}
interface StoreAction {
key: string;
store: Store;
actionCreator: ActionCreator
;
}
const actionMap: { [key: string]: StoreAction[] } = {};
export const registerBridgeStore = (
...stores: BridgeStore[]
): void => {
for (const store of stores) {
for (const [key, actionCreator] of Object.entries(store.actions)) {
if (actionMap[key] === undefined) {
actionMap[key] = [];
}
actionMap[key].push({
key,
store: store.store as unknown as Store