export default function createDevToolsStore(onDispatch) {
  let currentState = {
    committedState: {},
    stagedActions: [],
    computedStates: [],
    skippedActions: {},
    currentStateIndex: 0
  };
  let handleChangeState = null;
  let initiated = false;

  function dispatch(action) {
    if (action.type[0] !== '@') onDispatch(action);
    return action;
  }

  function getState() {
    return currentState;
  }

  function isSet() {
    return initiated;
  }

  function setState(state) {
    currentState = state;
    if (handleChangeState) handleChangeState();
    if (!initiated) initiated = true;
  }

  function subscribe(listener) {
    handleChangeState = listener;

    return function unsubscribe() {
      handleChangeState = null;
    };
  }

  return {
    dispatch,
    getState,
    liftedStore: {
      dispatch,
      getState,
      setState,
      subscribe,
      isSet
    }
  };
}

export default function createDevToolsStore(onDispatch) {
  let currentState = {
    committedState: {},
    stagedActions: [],
    computedStates: [],
    skippedActions: {},
    currentStateIndex: 0
  };
  let listeners = [];
  let initiated = false;

  function dispatch(action) {
    if (action.type[0] !== '@') onDispatch(action);
    return action;
  }

  function getState() {
    return currentState;
  }

  function isSet() {
    return initiated;
  }

  function setState(state) {
    currentState = state;
    listeners.forEach(listener => listener());
    initiated = true;
  }

  function subscribe(listener) {
    listeners.push(listener);

    return function unsubscribe() {
      const index = listeners.indexOf(listener);
      listeners.splice(index, 1);
    };
  }

  return {
    dispatch,
    getState,
    subscribe,
    liftedStore: {
      dispatch,
      getState,
      setState,
      subscribe,
      isSet
    }
  };
}

Revert "Allow only one listener to be subscribed to the background store"
Revert "Allow only one listener to be subscribed to the background store"

This reverts commit 598c160833271897c9f564b0bad7f71d2f8e39f3.
