2.0.8 • Published 4 years ago

@harveyw/electron-redux v2.0.8

Weekly downloads
125
License
MIT
Repository
github
Last release
4 years ago

electron-redux

build status package version code style: prettier

electron-redux data flow

Keeps your state in sync across all of your Electron processes by playing your actions in all of them.

// in the main process
import { syncMain } from "@mckayla/electron-redux";
const store = createStore(reducer, syncMain);
// in the renderer processes
import { syncRenderer } from "@mckayla/electron-redux";
const store = createStore(reducer, syncRenderer);

That's it! Just add these enhancers to where you initialize your store. As long as your reducers are pure/deterministic (which they already should be) your state should be reproduced accurately across all of the processes.

Actions

Actions MUST be FSA-compliant, i.e. have a type and payload property. Any actions not passing this test will be ignored and simply passed through to the next middleware.

NB: redux-thunk is not FSA-compliant out of the box, but can still produce compatible actions once the async action fires.

Actions MUST be serializable

  • Objects with enumerable properties
  • Arrays
  • Numbers
  • Booleans
  • Strings
  • Maps
  • Sets

Local actions

By default, all actions are played in all processes. If an action should only be played in the current thread, then you can set the scope meta property to local.

const myLocalActionCreator = () => ({
	type: "MY_ACTION",
	payload: 123,
	meta: {
		scope: "local", // only play the action locally
	},
});

We also provide a utility function for this

import { stopForwarding } from "@mckayla/electron-redux";
dispatch(stopForwarding(action));

Contributors

2.0.7

4 years ago

2.0.8

4 years ago

2.0.5

4 years ago

2.0.6

4 years ago

2.0.4

4 years ago

2.0.3

4 years ago