forked from klarna/electron-redux
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2ebd343
commit 5795a5a
Showing
7 changed files
with
43 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 9 additions & 7 deletions
16
packages/electron-redux/src/helpers/getInitialStateRenderer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
import { remote } from 'electron'; | ||
|
||
export default function getInitialStateRenderer() { | ||
const getReduxState = remote.getGlobal('getReduxState'); | ||
if (!getReduxState) { | ||
throw new Error( | ||
'Could not find reduxState global in main process, did you forget to call replayActionMain?', | ||
); | ||
export default function getInitialStateRenderer(ipc_event_name) { | ||
return function() { | ||
const getReduxState = remote.getGlobal('getReduxState'); | ||
if (!getReduxState || !getReduxState[ipc_event_name]) { | ||
throw new Error( | ||
'Could not find reduxState global in main process, did you forget to call replayActionMain?', | ||
); | ||
} | ||
return JSON.parse(getReduxState[ipc_event_name]()); | ||
} | ||
return JSON.parse(getReduxState()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,21 @@ | ||
import { ipcMain } from 'electron'; | ||
|
||
export default function replayActionMain(store) { | ||
/** | ||
* Give renderers a way to sync the current state of the store, but be sure | ||
* we don't expose any remote objects. In other words, we need our state to | ||
* be serializable. | ||
* | ||
* Refer to https://github.com/electron/electron/blob/master/docs/api/remote.md#remote-objects | ||
*/ | ||
global.getReduxState = () => JSON.stringify(store.getState()); | ||
export default function replayActionMain(ipc_event_name) { | ||
return function (store) { | ||
/** | ||
* Give renderers a way to sync the current state of the store, but be sure | ||
* we don't expose any remote objects. In other words, we need our state to | ||
* be serializable. | ||
* | ||
* Refer to https://github.com/electron/electron/blob/master/docs/api/remote.md#remote-objects | ||
*/ | ||
if(!global.getReduxState) | ||
global.getReduxState = {}; | ||
|
||
ipcMain.on('redux-action', (event, payload) => { | ||
store.dispatch(payload); | ||
}); | ||
global.getReduxState[ipc_event_name] = () => JSON.stringify(store.getState()); | ||
|
||
ipcMain.on(ipc_event_name, (event, payload) => { | ||
store.dispatch(payload); | ||
}); | ||
}; | ||
} |
10 changes: 6 additions & 4 deletions
10
packages/electron-redux/src/helpers/replayActionRenderer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
import { ipcRenderer } from 'electron'; | ||
|
||
export default function replayActionRenderer(store) { | ||
ipcRenderer.on('redux-action', (event, payload) => { | ||
store.dispatch(payload); | ||
}); | ||
export default function replayActionRenderer(ipc_event_name) { | ||
return function (store) { | ||
ipcRenderer.on(ipc_event_name, (event, payload) => { | ||
store.dispatch(payload); | ||
}); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters