All files / middleware forwardToRenderer.js

94.44% Statements 17/18
83.33% Branches 10/12
100% Functions 5/5
100% Lines 15/15
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35        4x 4x         4x 4x 3x 1x   2x 2x 1x 1x 3x     1x 1x 3x           4x        
import { BrowserWindow } from 'electron';
import validateAction from '../helpers/validateAction';
import windowManager from '../helpers/windowManager';
 
const forwardToRenderer = () => next => (action) => {
  Iif (!validateAction(action)) return next(action);
 
  // Only actions specified with scope in meta
  // will be send to correspond renderer process
 
  const scope = action.meta ? action.meta.scope : null;
  if (scope) {
    if (typeof scope === 'symbol') {
      windowManager.get(scope)
      .webContents.send('redux-action', action);
    } else Eif (typeof scope === 'string') {
      if (scope === '__ALL__') {
        const allWindows = BrowserWindow.getAllWindows();
        allWindows.forEach(({ webContents }) => {
          webContents.send('redux-action', action);
        });
      } else {
        const openWindows = windowManager.getAll(action.meta.scope);
        openWindows.forEach(({ webContents }) => {
          webContents.send('redux-action', action);
        });
      }
    }
  }
 
  return next(action);
};
 
export default forwardToRenderer;