@zubridge/electron
Version:
A streamlined state management library for Electron applications using Zustand.
57 lines (56 loc) • 2.19 kB
JavaScript
import { createCoreBridge, createBridgeFromStore } from './bridge.js';
import { createDispatch } from './utils/dispatch.js';
import { removeStateManager } from './utils/stateManagerRegistry.js';
/**
* Export the core bridge creation function for custom implementations
*/
export { createCoreBridge };
/**
* Creates a bridge between a Zustand store and the renderer process
*/
export function createZustandBridge(store, windows, options) {
// Create the core bridge with the store
const coreBridge = createBridgeFromStore(store, windows, options);
// Create the dispatch function with the same store
const dispatchFn = createDispatch(store, options);
// Return bridge with all functionality
return {
subscribe: coreBridge.subscribe,
unsubscribe: coreBridge.unsubscribe,
getSubscribedWindows: coreBridge.getSubscribedWindows,
destroy: () => {
coreBridge.destroy();
// Clean up the state manager from the registry
removeStateManager(store);
},
dispatch: dispatchFn,
};
}
/**
* Creates a bridge between a Redux store and the renderer process
*/
export function createReduxBridge(store, windows, options) {
// Create the core bridge with the store
const coreBridge = createBridgeFromStore(store, windows, options);
// Create the dispatch function with the same store
const dispatchFn = createDispatch(store, options);
// Return bridge with all functionality
return {
subscribe: coreBridge.subscribe,
unsubscribe: coreBridge.unsubscribe,
getSubscribedWindows: coreBridge.getSubscribedWindows,
destroy: () => {
coreBridge.destroy();
// Clean up the state manager from the registry
removeStateManager(store);
},
dispatch: dispatchFn,
};
}
/**
* Legacy bridge alias for backward compatibility
* @deprecated This is now an alias for createZustandBridge and uses the new IPC channels.
* Please update your code to use createZustandBridge directly in the future.
*/
export const mainZustandBridge = createZustandBridge;
export { createDispatch } from './utils/dispatch';