Update content/tutorials/build-apps/build-a-desktop-wallet-in-javascript.md

Co-authored-by: Jackson Mills <aim4math@gmail.com>
This commit is contained in:
Alexander Busse
2023-07-10 15:40:08 +02:00
committed by GitHub
parent ea38cc9c29
commit 5097179605

View File

@@ -308,7 +308,7 @@ Here we first call our helper function `getValidatedLedgerIndex()` and then broa
This example shows how to do Inter Process Communication (IPC) in Electron. Technically, JavaScript has no true parallel processes or threading because it follows a single-threaded event-driven paradigm. Nonetheless Electron provides us with two IPC modules called `ipcMain` and `ipcRenderer`. We can roughly equate `ipcMain` to a backend process and `ipcRenderer` to a frontend process when we think in terms of client-server applications. It works as follows:
1. We started by creating a function that enables the frontend to subscribe to backend events via the ContextBridge (in `view/preload.js`)
1. We started by creating a function that enables the frontend to subscribe to backend events via the `ContextBridge` (`onUpdateLedgerIndex` in `view/preload.js`)
2. Then we make the function available by putting it in a preloader script to ensure it is loaded and can be used by the frontend.
3. On the frontend, we can then use that function to attach a callback that handles frontend updates when the event is dispatched. We could do this in the console, in a `<script>` tag in the frontend or in our case in a separate file.
4. Lastly, we dispatch the event from the main logic in `index.js`via `appWindow.webContents.send('update-ledger-index', value)`.