getState(configure, store => {
   onConnect(
     () => ({ name: 'init', state: { counter: store.getState().counter } }),
     {
       'redux-notify': (message) => { store.dispatch(receiveNotification(message.action)); }
     }
   );
   callback(store);
 });
import { onConnect, onMessage, sendToTab } from 'crossmessaging';
import updateState from 'remotedev-app/lib/store/updateState';
import syncOptions from '../options/syncOptions';
import createMenu from './contextMenus';
import openDevToolsWindow from './openWindow';
let connections = {};
let catchedErrors = {};

window.syncOptions = syncOptions; // Used in the options page

const naMessage = { type: 'NA' };

// Connect to devpanel
onConnect((tabId) => {
  if (tabId !== store.id) return naMessage;
  return {};
}, {}, connections);

function handleInstancesChanged(instance, name) {
  window.store.liftedStore.instances[instance] = name || instance;
}

// Receive message from content script
function messaging(request, sender, sendResponse) {
  const tabId = sender.tab ? sender.tab.id : sender.id;
  if (tabId) {
    if (request.type === 'PAGE_UNLOADED') {
      handleInstancesChanged(tabId, undefined, true);
      if (connections[tabId]) connections[tabId].postMessage(naMessage);
      if (window.store.liftedStore.instances[tabId]) {
        delete window.store.liftedStore.instances[tabId];
  if (!port.sender.tab && !port.sender.id) {
    monitorInstances(false);
    return;
  }
  const id = getId(port);
  delete tabConnections[id];
  if (panelConnections[id]) panelConnections[id].postMessage(naMessage);
  if (window.store.liftedStore.instances[id]) {
    delete window.store.liftedStore.instances[id];
    window.store.liftedStore.deleteInstance(id);
  }
}

onConnect(undefined, {
  INIT_PANEL: initPanel,
  INIT_INSTANCE: initInstance,
  RELAY: (msg, port) => { messaging(msg.message, port.sender); }
}, panelConnections, disconnect);

function handleInstancesChanged(instance, name) {
  window.store.liftedStore.instances[instance] = name || instance;
}

// Receive message from content script
function messaging(request, sender, sendResponse) {
  const tabId = sender.tab ? sender.tab.id : sender.id;
  if (tabId) {
    if (request.type === 'GET_OPTIONS') {
      window.syncOptions.get(options => {
        sendResponse({options: options});
      });