久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

ElectronJS - 在 Windows 之間共享 redux 存儲(chǔ)?

ElectronJS - sharing redux store between windows?(ElectronJS - 在 Windows 之間共享 redux 存儲(chǔ)?)
本文介紹了ElectronJS - 在 Windows 之間共享 redux 存儲(chǔ)?的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

我有一個(gè)基于 electron-react-boilerplate 的電子應(yīng)用程序.

I have an electron app based on electron-react-boilerplate.

現(xiàn)在,我已經(jīng)按照我的意愿運(yùn)行了一個(gè)窗口,我開(kāi)始創(chuàng)建一個(gè)新窗口.

Now, that I have one window running as I wanted it to run, I started to create a new window.

我目前有 2 個(gè) html 文件 - 每個(gè)窗口一個(gè) - 包含 div 根:

I currently have 2 html files - one for each window - containing div roots:

  1. <div data-root id="main_root"></div>
  2. <div data-root id="second_root"></div>

我的 index.js 文件是用于渲染 React 應(yīng)用程序的響應(yīng),如下所示:

My index.js file that is response for rendering the react app looks like this:

import React from 'react';
import { render } from 'react-dom';
import { AppContainer } from 'react-hot-loader';
import HomeRoot from './roots/HomeRoot';
import HoverRoot from './roots/HoverRoot';
import { configureStore, history } from './store/configureStore';

const store = configureStore();

const rootMapping = {
  main_root: {
    name: 'HomeRoot',
    Component: HomeRoot,
    getNextRoot: () => require('./roots/HomeRoot'),
  },
  second_root: {
    name: 'SecondRoot',
    Component: SecondRoot,
    getNextRoot: () => require('./roots/SecondRoot'),
  },
};

const renderDesiredRoot = () => {
  const rootElementID = document.querySelector('[data-root]').id;
  const root = rootMapping[rootElementID];
  if (!root) throw Error('There is no such Root component!');
  const { Component, getNextRoot, name } = root;
  render(
    <AppContainer>
      <Component store={store} history={history} />
    </AppContainer>,
    document.getElementById(rootElementID),
  );
  if (module.hot) {
    module.hot.accept(`./roots/${name}`, () => {
      const NextRoot = getNextRoot();
      render(
        <AppContainer>
          <NextRoot store={store} history={history} />
        </AppContainer>,
        document.getElementById(rootElementID),
      );
    });
  }
};

renderDesiredRoot();

它的作用是檢查哪個(gè) div 根可用,并呈現(xiàn)適當(dāng)?shù)慕M件.

What it does, it checks which div root is available, and renders proper components.

我的問(wèn)題

如何創(chuàng)建將在 BrowserWindow 實(shí)例之間共享的商店?我已經(jīng)研究了 2 個(gè) npm 包(electron-reduxredux-electron-store),在這種情況下,它們似乎不是我的解決方案.

How can I make a store that will be shared accross the BrowserWindow instances? I already looked into 2 npm packages (electron-redux and redux-electron-store) and they do not seem as a solution for me in this case.

推薦答案

我嘗試使用這種非常簡(jiǎn)單的方法,它幾乎可以完美運(yùn)行,但有時(shí)它會(huì)凍結(jié)(我不確定到底是什么讓它凍結(jié)).也許這對(duì)任何人都有用,如果有人發(fā)現(xiàn)導(dǎo)致凍結(jié)問(wèn)題的原因,請(qǐng)告訴我們.

I tried using this very simple approach, it works almost perfectly, but sometimes it's freezing (I'm not sure yet what exactly is making it to freeze). Maybe this could be useful to anyone, and if someone finds out what is causing the freezing issue, please let us know.

Redux 存儲(chǔ)代碼(所有窗口都使用相同的代碼):

Redux store code (this same code is used by all windows):

export const store = window.opener?.store || createStore(...);

Object.assign(window, { store });

然后我需要從主窗口的渲染器進(jìn)程中打開(kāi)新的電子窗口:

Then I need to open new electron window from a renderer process of the main window using:

const newWindow = window.open("/path", "someName");

而且我們?cè)谥鬟M(jìn)程上也需要這段代碼:

And we also need this code on the main process:

win.webContents.on("new-window", function (e, url, frameName, _, options) {
  e.preventDefault();

  if (frameName === "someName")
    e.newGuest = new BrowserWindow({ ...options, width: 300, height: 200, /* anything else you wanna add */ });
});

這篇關(guān)于ElectronJS - 在 Windows 之間共享 redux 存儲(chǔ)?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

How to fix BrowserWindow is not a constructor error when creating child window in Electron renderer process(在 Electron 渲染器進(jìn)程中創(chuàng)建子窗口時(shí)如何修復(fù) BrowserWindow 不是構(gòu)造函數(shù)錯(cuò)誤) - IT屋-程序員軟件開(kāi)發(fā)技術(shù)
mainWindow.loadURL(quot;https://localhost:3000/quot;) show white screen on Electron app(mainWindow.loadURL(https://localhost:3000/) 在 Electron 應(yīng)用程序上顯示白屏)
Electron webContents executeJavaScript : Cannot execute script on second on loadURL(Electron webContents executeJavaScript:無(wú)法在第二個(gè) loadURL 上執(zhí)行腳本)
how to use electron browser window inside components in angular-cli?(如何在angular-cli的組件內(nèi)使用電子瀏覽器窗口?)
How to access camera/webcamera inside electron app?(如何在電子應(yīng)用程序中訪問(wèn)相機(jī)/網(wǎng)絡(luò)攝像頭?)
How to getCurrentPosition via navigator.geolocation in Electron app?(如何通過(guò)電子應(yīng)用程序中的 navigator.geolocation 獲取當(dāng)前位置?)
主站蜘蛛池模板: 国产日韩欧美一区二区在线播放 | 国产九九av | 天堂综合 | 免费观看av网站 | 国产伦精品一区二区三区精品视频 | 国产欧美精品 | 欧美另类视频 | 成人看片在线观看 | 久久久久国产精品午夜一区 | 成人精品 | 欧美一区二区三区视频在线观看 | 国产成人自拍一区 | 精精国产xxxx视频在线 | 中文在线www | 色婷婷久久久亚洲一区二区三区 | 国产乱码一二三区精品 | 久久久久高清 | 欧美国产精品一区二区三区 | 久久久亚洲一区 | 久久综合国产精品 | www日韩| 亚洲一区二区三 | 二区中文字幕 | 欧美精品一区二区三区在线播放 | 日韩在线观看视频一区 | 亚洲3级| 国产精品久久久久久吹潮 | 国产日韩欧美一区二区 | 欧美日韩国产精品一区二区 | 久久综合久色欧美综合狠狠 | 久久综合久久自在自线精品自 | 欧美mv日韩mv国产网站91进入 | 国产精品久久久久久久久久久新郎 | 久久亚洲国产精品日日av夜夜 | 91视频一88av| 欧美成视频 | 欧美成人免费在线 | 天天拍天天草 | 国产精品久久久久久久一区二区 | 欧美一级大黄 | 日本精品网站 |