GithubHelp home page GithubHelp logo

tessro / electron-redux Goto Github PK

View Code? Open in Web Editor NEW

This project forked from aslilac/electron-redux

0.0 2.0 0.0 1.62 MB

Use redux in the main and browser processes in electron

License: MIT License

JavaScript 42.78% HTML 2.70% TypeScript 54.51%

electron-redux's Introduction

electron-redux

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 '@paulrosania/electron-redux';
const store = createStore(reducer, applyMiddleware(syncMain));
// in the renderer processes
import { syncRenderer, wrapRendererReducer } from '@paulrosania/electron-redux';
const store = createStore(wrapRendererReducer(reducer), applyMiddleware(syncRenderer));

That's it! Just add each middleware to where you initialize your store, and wrap the renderer reducer so it can receive state from the main process. 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

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 "@paulrosania/electron-redux";
dispatch(stopForwarding(action));

Contributors

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.