https://github.com/dilatorily/redux-ipc-electron
Redux IPC Middleware for Electron
https://github.com/dilatorily/redux-ipc-electron
electron ipc middleware redux
Last synced: about 2 months ago
JSON representation
Redux IPC Middleware for Electron
- Host: GitHub
- URL: https://github.com/dilatorily/redux-ipc-electron
- Owner: Dilatorily
- License: mit
- Created: 2017-02-24T05:32:04.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-02-26T06:51:17.000Z (over 9 years ago)
- Last Synced: 2025-03-03T07:46:11.481Z (over 1 year ago)
- Topics: electron, ipc, middleware, redux
- Language: JavaScript
- Size: 43 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# redux-ipc-electron
[](https://www.npmjs.com/package/redux-ipc-electron)
[](https://travis-ci.org/Dilatorily/redux-ipc-electron)
[](https://codecov.io/gh/Dilatorily/redux-ipc-electron)
Redux IPC Middleware for Electron
## Installation
Use NPM to install this module:
```bash
$ npm install --save redux-ipc-electron
```
## Usage
This library uses Electron's IPC to synchronizes the Redux store between the main process and the renderer process(es).
Use the Redux middleware in the renderer Redux store.
```javascript
import { createMiddleware as ReduxIPCMiddleware } from 'redux-ipc-electron';
// ...
createStore(reducers, preloadedState, applyMiddleware(thunk, ReduxIPCMiddleware(), logger));
```
Listen to the IPC events in the main process.
```javascript
import { createMainListeners } from 'redux-ipc-electron';
// ...
createMainListeners();
```
That's it! The main process will now receive the renderer's Redux store on every action.
## API
This library exposes 4 functions in its API.
### initializeStore([preloadedState])
Use this function in the main process to initialize the Redux store in the main process. It returns the main process Redux store.
The `preloadedState` will create the store using it as its initial value.
### createMainListeners([onSync])
Use this function in the main process to listen to Electron IPC events.
The `onSync` callback will be called with the updated Redux store on every IPC sync events.
### getMainState([identifier])
Use this function in the renderer process to get a part of the main process Redux store identified by the `identifier` parameter.
A default `identifier` will be used if it is omitted.
### createMiddleware([identifier], [predicate])
Use this function in the renderer process to create the middleware used in the Redux store.
The `identifier` should be used if there are multiple renderer processes. A default `identifier` will be used if it is omitted.
The `predicate` function is called with the store's `state` as its parameter. An identity function will be used if it is omitted.
## [License](LICENSE)
This repository is open source and distributed under the MIT License.