Redux Electron IPC Middleware
A Redux middleware to reduce code around ipc calls in an Electron application. You can send and receive IPC events with a simple api.
Install
npm
npm install --save redux-electron-ipc
Usage
Check out the full demo application.
Window
;;;; // register an action creator to an ipc channel (key/channel, value/action creator)const ipc = ; const store = ; // send a message with arguments through the `send` utility functionstore;
Main
// your regular ipc setupconst electron = ;const ipcMain = electron; ... // pong event with arguments back to calleripcMain;
API
redux-electron-ipc
has a default constructor function for creating ipc
middleware, and a named send
utility function.
IpcMiddleware Action
Events
Each key on the events
object (default: {}
) registers a single ipc channel
response. The key designates the ipc
channel; the value is a redux action
creator to be dispatched.
{ return type: 'YOUR_ACTION_TYPE' ... optional mapping of arguments ... }
Examples
Sending an IPC event
Use the utility function send
to issue an ipc message to the main thread. The
method signature is the same as ipcRenderer's send.
Behind the scenes, the ipc middleware will trigger the ipc on the given channel with any number of arguments.
; store;
Receiving an IPC event
To receive events, register a channel response when configuring the middleware.
const ipc = ; const store = ;
redux-thunk
?
What about redux-electron-ipc
supports thunks out of the box as long as you install redux-thunk
and apply the thunk middleware before the ipc middleware.
Example
const ipc = ;const store = ;
Questions
For any questions, please open an issue. Pull requests (with tests) are appreciated.