import { log, warn, error } from '@vizality/util/logger';

/**
 *
 */

import { FluxDispatcher } from '@vizality/webpack';

export const labels = [ 'Global' ];

export default main => {
  const ogDispatch = FluxDispatcher.dispatch;
  try {
    FluxDispatcher.dispatch = function (args) {
      if (vizality.settings.get('fluxDispatcherLogs', false)) {
        vizality.log(vizality._labels.concat('Dispatcher'), args);
      }
      this.wait(() => this._dispatch(args));
    };
  } catch (err) {
    return main.error(main._labels.concat(labels.concat('Dispatcher')), err);
  }
  return () => FluxDispatcher.dispatch = ogDispatch;
};
