<commit_before>/* eslint-disable no-console */
import { CONFIG } from '../constants';
import { Socket } from 'phoenix';
import { startPlugin } from '..';
import listenAuth from './listenAuth';
import handleNotifications from './handleNotifications';
import handleWork from './handleWork';
import renderIcon from './renderIcon';

export const startChromePlugin = (auth, chrome, enhancer, socketConstructor = Socket) => {
  const reloader = () => window.location.reload(true);
  const plugin = startPlugin({ auth, enhancer, reloader, socketConstructor });
  const store = plugin.getStore();

  const getStore = () => store;

  listenAuth(store, chrome);
  handleNotifications(store, chrome);
  renderIcon(store, chrome);
  handleWork(store, chrome);

  if (CONFIG.env === 'dev') {
    // redux dev tools don't work with the plugin, so we have a dumb
    // replacement.
    store.subscribe(() => {
      const { worker, socket } = store.getState();
      console.log('Worker:', worker.toJS(), 'Socket:', socket.toJS());
    });
  }

  return { getStore };
};<commit_msg>Add plugin state to logging<commit_after>/* eslint-disable no-console */
import { CONFIG } from '../constants';
import { Socket } from 'phoenix';
import { startPlugin } from '..';
import listenAuth from './listenAuth';
import handleNotifications from './handleNotifications';
import handleWork from './handleWork';
import renderIcon from './renderIcon';

export const startChromePlugin = (auth, chrome, enhancer, socketConstructor = Socket) => {
  const reloader = () => window.location.reload(true);
  const plugin = startPlugin({ auth, enhancer, reloader, socketConstructor });
  const store = plugin.getStore();

  const getStore = () => store;

  listenAuth(store, chrome);
  handleNotifications(store, chrome);
  renderIcon(store, chrome);
  handleWork(store, chrome);

  if (CONFIG.env === 'dev') {
    // redux dev tools don't work with the plugin, so we have a dumb
    // replacement.
    store.subscribe(() => {
      const { worker, socket, plugin: pluginState } = store.getState();
      console.log('Worker:', worker.toJS(),
                  'Socket:', socket.toJS(),
                  'Plugin:', pluginState.toJS());
    });
  }

  return { getStore };
};
{'fraction_non_alphanumeric': 0.15102770330652368, 'fraction_numerical': 0.0, 'mean_word_length': 3.8047210300429186, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7419183', 'n_tokens_mistral': 642, 'n_tokens_neox': 619, 'n_words': 188}