<commit_before>const Rx = require('rxjs/Rx');
const Observable = Rx.Observable;

const jupyterPaths = require('jupyter-paths');

import { MERGE_CONFIG } from '../constants';

export const LOAD_CONFIG = 'LOAD_CONFIG';
export const loadConfig = () => ({type: LOAD_CONFIG });

const readFileObservable = (filename, ...args) =>
  Observable.create(observer => {
    fs.readFile(filename, ...args, (error, data) => {
      if (error) {
        observer.error(error);
      } else {
        observer.next(data);
        observer.complete();
      }
    })
  });

export const configLoaded = (config) => ({
  type: MERGE_CONFIG,
  config,
});

export const getConfigFilePath = () => {
  `${jupyterPaths.dataDir()[0]}/nteract.json`
}

export const loadConfigEpic = actions =>
  actions.ofType(LOAD_CONFIG)
    .do(action =>
      readFileObservable(getConfigFilePath())
        .map(JSON.parse)
        .flatMap(({ config }) =>
          Observable.of(
            configLoaded(config),
          )
        )
        .catch((err) =>
          Observable.of({ type: 'ERROR', payload: err, error: true })
        )
      );
<commit_msg>fix(config): Don't expect top level config key in config<commit_after>const Rx = require('rxjs/Rx');
const Observable = Rx.Observable;

const jupyterPaths = require('jupyter-paths');

import { MERGE_CONFIG } from '../constants';

export const LOAD_CONFIG = 'LOAD_CONFIG';
export const loadConfig = () => ({type: LOAD_CONFIG });

const readFileObservable = (filename, ...args) =>
  Observable.create(observer => {
    fs.readFile(filename, ...args, (error, data) => {
      if (error) {
        observer.error(error);
      } else {
        observer.next(data);
        observer.complete();
      }
    })
  });

export const configLoaded = (config) => ({
  type: MERGE_CONFIG,
  config,
});

export const getConfigFilePath = () => {
  `${jupyterPaths.dataDir()[0]}/nteract.json`
}

export const loadConfigEpic = actions =>
  actions.ofType(LOAD_CONFIG)
    .do(action =>
      readFileObservable(getConfigFilePath())
        .map(JSON.parse)
        .map(configLoaded(config))
        )
        .catch((err) =>
          Observable.of({ type: 'ERROR', payload: err, error: true })
        )
      );

{'fraction_non_alphanumeric': 0.15858041329739442, 'fraction_numerical': 0.0008984725965858042, 'mean_word_length': 2.839655172413793, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 22, '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': '1853981', 'n_tokens_mistral': 702, 'n_tokens_neox': 699, 'n_words': 141}