<commit_before>'use strict';

const alt = require('../alt');
const _ = require('lodash');
const DataStore = require('./DataStore');
const CFFActions = require('../actions/CFFActions');
const ManualActions = require('../actions/ManualActions');
const MatchActions = require('../actions/MatchActions');


class ManualCFFDataStore extends DataStore {

  constructor() {
    super(ManualCFFDataStore);
    this.bindActions(CFFActions);
    this.bindActions(ManualActions);
    this.bindAction(MatchActions.commitMatchesSuccess, this.update);
    this.newLine = {
      loading: false,
      show: false,
      error: undefined
    };
    this.outdated = false;
  }

  onGetManual() {
    this.outdated = false;
    this.deleteAll();
  }

  onGetManualSuccess(data) {
    // insert payments
    data.forEach((line) => this.insert(line._id, line));
  }

  onDeleteManualLine(lineId) {
    this.setLoading(lineId, true);
  }

  onDeleteManualLineSuccess(lineId) {
    this.delete(lineId);
  }

  onDeleteManualLineFail(res) {
    this.setLoading(res._id, false);
    this.setError(res._id, res.error.data.message);
  }

  _resetNewLine() {
    this.newLine.loading = false;
    this.newLine.show = false;
    this.newLine.error = undefined;
  }

  onHideNewLine() {
    this._resetNewLine();
  }

  onShowNewLine() {
    this.newLine.show = true;
  }

  onSetNewLineError(err) {
    this.newLine.error = err;
  }

  onSetLineError(data) {
    this.setError(data._id, data.error);
  }

  onCreateManualLine() {
    this.newLine.loading = true;
  }

  onCreateManualLineSuccess(newLine) {
    this._resetNewLine();
    this.insert(newLine._id, newLine);
  }

  onCreateManualLineFail(err) {
    this.newLine.loading = false;
    this.newLine.error = err.data.message;
  }

  onSaveManualLine(line) {
    this.setLoading(line._id, true);
    this.setError(line._id, undefined);
  }

  onSaveManualLineSuccess(line) {
    this.upsert(line._id, line);
    this.resetLine(line._id);
  }

  onSaveManualLineFail(res) {
    this.setLoading(res._id, false);
    this.setError(res._id, res.error.data.message);
  }

  resetLine(lineId) {
    this.setLoading(lineId, false);
    this.setError(lineId, undefined);
  }

  setLoading(lineId, value) {
    this.update(lineId, {loading: value});
  }

  setError(lineId, value) {
    this.update(lineId, {error: value});
  }

  update() {
    this.outdated = true;
  }

}

module.exports = alt.createStore(ManualCFFDataStore, 'ManualCFFDataStore');
<commit_msg>fixed ManualCffDataStore: update function was overriding DataStore one. renamed to refresh.<commit_after>'use strict';

const alt = require('../alt');
const _ = require('lodash');
const DataStore = require('./DataStore');
const CFFActions = require('../actions/CFFActions');
const ManualActions = require('../actions/ManualActions');
const MatchActions = require('../actions/MatchActions');


class ManualCFFDataStore extends DataStore {

  constructor() {
    super(ManualCFFDataStore);
    this.bindActions(CFFActions);
    this.bindActions(ManualActions);
    this.bindAction(MatchActions.commitMatchesSuccess, this.refresh);
    this.newLine = {
      loading: false,
      show: false,
      error: undefined
    };
    this.outdated = false;
  }

  onGetManual() {
    this.outdated = false;
    this.deleteAll();
  }

  onGetManualSuccess(data) {
    // insert payments
    data.forEach((line) => this.insert(line._id, line));
  }

  onDeleteManualLine(lineId) {
    this.setLoading(lineId, true);
  }

  onDeleteManualLineSuccess(lineId) {
    this.delete(lineId);
  }

  onDeleteManualLineFail(res) {
    this.setLoading(res._id, false);
    this.setError(res._id, res.error.data.message);
  }

  _resetNewLine() {
    this.newLine.loading = false;
    this.newLine.show = false;
    this.newLine.error = undefined;
  }

  onHideNewLine() {
    this._resetNewLine();
  }

  onShowNewLine() {
    this.newLine.show = true;
  }

  onSetNewLineError(err) {
    this.newLine.error = err;
  }

  onSetLineError(data) {
    this.setError(data._id, data.error);
  }

  onCreateManualLine() {
    this.newLine.loading = true;
  }

  onCreateManualLineSuccess(newLine) {
    this._resetNewLine();
    this.insert(newLine._id, newLine);
  }

  onCreateManualLineFail(err) {
    this.newLine.loading = false;
    this.newLine.error = err.data.message;
  }

  onSaveManualLine(line) {
    this.setLoading(line._id, true);
    this.setError(line._id, undefined);
  }

  onSaveManualLineSuccess(line) {
    this.upsert(line._id, line);
    this.resetLine(line._id);
  }

  onSaveManualLineFail(res) {
    this.setLoading(res._id, false);
    this.setError(res._id, res.error.data.message);
  }

  resetLine(lineId) {
    this.setLoading(lineId, false);
    this.setError(lineId, undefined);
  }

  setLoading(lineId, value) {
    this.update(lineId, {loading: value});
  }

  setError(lineId, value) {
    this.update(lineId, {error: value});
  }

  refresh() {
    this.outdated = true;
  }

}

module.exports = alt.createStore(ManualCFFDataStore, 'ManualCFFDataStore');

{'fraction_non_alphanumeric': 0.1410763751483973, 'fraction_numerical': 0.0, 'mean_word_length': 3.4774136403897256, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '808163', 'n_tokens_mistral': 1791, 'n_tokens_neox': 1737, 'n_words': 256}