samiskin / redux-electron-store

⎋ A redux store enhancer that allows automatic synchronization between electron processes
MIT License
375 stars 32 forks source link

Actions from main process dont forward to render process #44

Closed borzovplus closed 7 years ago

borzovplus commented 7 years ago

I'm copied code from readme to my project (create store). Please help me to understand why actions from render to main process forwarded, BUT actions from main to render NOT. Could you show a simple example of working code ?

samiskin commented 7 years ago

The most minimal example of using this would just be

import { electronEnhancer } from 'redux-electron-store';
let store = createStore(reducer, initialState, electronEnhancer());

The example in my Readme, in a bit of a confusing fashion, had an example of using a filter included in its "Usage" example, which might've been why you had your issue. I've updated it to be more clear and only mention the filter in the Filters section.

samiskin commented 7 years ago

Based on https://github.com/electron/electron-quick-start


// store.js
const { createStore } = require('redux');
const { electronEnhancer } = require('redux-electron-store');

const counter = (state, action) =>
  action.type === 'INCREMENT' ? {count: state.counter + 1} : state;

let store = createStore(counter, {count: 0}, electronEnhancer());
store.subscribe(() => console.log(store.getState()));

module.exports = store;

// renderer.js
const store = require('./store');
store.dispatch({type: 'INCREMENT'});

// main.js
// ... all the setup code in electron-quick-start's main.js
const store = require('./store');
setTimeout(() => store.dispatch({type: 'INCREMENT'}), 3000);
borzovplus commented 7 years ago

the module store.js must be the same for render and main ?

samiskin commented 7 years ago

They should be using the same root reducer

borzovplus commented 7 years ago

But the render and main processes should have a different reducer and actions in my project.. Thank you. I found how to do this without using this lib.