<commit_before>import { ActionsObservable } from 'redux-observable';
import { writeFileObservable } from '../../utils/fs';

const Rx = require('rxjs/Rx');
const commutable = require('commutable');

const Observable = Rx.Observable;

export const SAVE = 'SAVE';
export const SAVE_AS = 'SAVE_AS';
export const CHANGE_FILENAME = 'CHANGE_FILENAME';
export const DONE_SAVING = 'DONE_SAVING';

export const changeFilename = filename => ({ type: CHANGE_FILENAME, filename });
export const save = (filename, notebook) => ({ type: SAVE, filename, notebook });
export const saveAs = (filename, notebook) => ({ type: SAVE_AS, filename, notebook });
export const doneSaving = () => ({ type: DONE_SAVING });

export function saveEpic(action$) {
  return action$.ofType(SAVE)
    .do(action => {
      // If there isn't a filename, save-as it instead
      if (!action.filename) {
        throw new Error('save needs a filename');
      }
    })
    .mergeMap(action =>
      writeFileObservable(action.filename,
        JSON.stringify(
          commutable.toJS(
            action.notebook.update('cellMap', (cells) =>
              cells.map((value) =>
                value.delete('inputHidden').delete('outputHidden').delete('status')))),
          null,
          1))
        .catch(error => {
          const input$ = Observable.of({ type: 'SAVING_ERROR' });
          return new ActionsObservable(input$);
        })
        .map(doneSaving)
        // .startWith({ type: START_SAVING })
        // since SAVE effectively acts as the same as START_SAVING
        // you could just look for that in your reducers instead of START_SAVING
    );
}

export function saveAsEpic(actions) {
  return actions.ofType(SAVE_AS)
    .mergeMap(action => [
      changeFilename(action.filename),
      save(action.filename, action.notebook),
    ]);
}<commit_msg>chore(SavingEpic): Change observable on error.<commit_after>import { ActionsObservable } from 'redux-observable';
import { writeFileObservable } from '../../utils/fs';

const Rx = require('rxjs/Rx');
const commutable = require('commutable');

const Observable = Rx.Observable;

export const SAVE = 'SAVE';
export const SAVE_AS = 'SAVE_AS';
export const CHANGE_FILENAME = 'CHANGE_FILENAME';
export const DONE_SAVING = 'DONE_SAVING';

export const changeFilename = filename => ({ type: CHANGE_FILENAME, filename });
export const save = (filename, notebook) => ({ type: SAVE, filename, notebook });
export const saveAs = (filename, notebook) => ({ type: SAVE_AS, filename, notebook });
export const doneSaving = () => ({ type: DONE_SAVING });

export function saveEpic(action$) {
  return action$.ofType(SAVE)
    .do(action => {
      // If there isn't a filename, save-as it instead
      if (!action.filename) {
        throw new Error('save needs a filename');
      }
    })
    .mergeMap(action =>
      writeFileObservable(action.filename,
        JSON.stringify(
          commutable.toJS(
            action.notebook.update('cellMap', (cells) =>
              cells.map((value) =>
                value.delete('inputHidden').delete('outputHidden').delete('status')))),
          null,
          1))
        .catch(error => {
          const input$ = Observable.of(error);
          return new ActionsObservable(input$);
        })
        .map(doneSaving)
        // .startWith({ type: START_SAVING })
        // since SAVE effectively acts as the same as START_SAVING
        // you could just look for that in your reducers instead of START_SAVING
    );
}

export function saveAsEpic(actions) {
  return actions.ofType(SAVE_AS)
    .mergeMap(action => [
      changeFilename(action.filename),
      save(action.filename, action.notebook),
    ]);
}
{'fraction_non_alphanumeric': 0.13324324324324324, 'fraction_numerical': 0.0005405405405405405, 'mean_word_length': 3.0272034820457017, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, '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': '4124407', 'n_tokens_mistral': 1109, 'n_tokens_neox': 1076, 'n_words': 278}