@zubridge/electron
Version:
A streamlined state management library for Electron applications using Zustand.
33 lines (32 loc) • 1.23 kB
JavaScript
import { resolveHandler } from '../utils/handler-resolution.js';
/**
* Creates a state manager adapter for Redux stores
*
* This adapter connects a Redux store to the Zubridge bridge,
* allowing it to be used with the Electron IPC system.
*/
export function createReduxAdapter(store, options) {
return {
getState: () => store.getState(),
subscribe: (listener) => store.subscribe(() => listener(store.getState())),
processAction: (action) => {
try {
// First check if we have a custom handler for this action type
if (options?.handlers) {
// Try to resolve a handler for this action type
const handler = resolveHandler(options.handlers, action.type);
if (handler) {
handler(action.payload);
return;
}
}
// For Redux, we dispatch all actions to the store
// with our standard Action format
store.dispatch(action);
}
catch (error) {
console.error('Error processing Redux action:', error);
}
},
};
}