gitmyhub

redux-electron-store

JavaScript ★ 3 updated 10y ago ⑂ fork

A redux implementation that synchronizes itself between Electron processes

Keeps separate Redux stores in sync across an Electron app's main and renderer processes, with filters so each window only gets the data it needs.

JavaScriptReduxElectronsetup: moderatecomplexity 3/5

Redux Electron Store Explained

This library solves a specific problem for developers building desktop applications with Electron: keeping data in sync across different parts of the app. Electron apps have a main process (the backbone of the app) and one or more renderer processes (each window or tab). When you use Redux, a popular way to manage app data, you normally have one store. This library lets you have separate Redux stores in each process while keeping them automatically synchronized, so changes made in one window instantly appear in others.

Here's how it works at a high level. The library acts as a middleman that intercepts changes to your Redux store. When something changes in the main process, it sends a message to any renderer processes that need to know about it. But here's the clever part: you can tell each renderer exactly what data it cares about using a "filter." So a notifications window only gets updates about notifications and display settings, not unrelated app data. This saves bandwidth and keeps your app performant. The synchronization happens through Electron's built-in messaging system, so everything feels instant to the user.

A concrete example: imagine a Slack-like desktop app. The main process holds all the team data, messages, and settings. You open a notifications popup window (a separate renderer process) that only needs to know about notifications, the notification position on screen, and team icons. Instead of sending every single app update to that window, the filter makes sure it only receives updates relevant to those three things. Any other changes—like someone typing in a channel—don't cause unnecessary updates to the popup.

The main limitation to be aware of is that this library requires your data to be immutable, meaning you can't change objects directly; you have to create new copies when making updates. This is actually a common best practice in Redux anyway, so it's not usually a problem for experienced users.

Where it fits