<commit_before>import {settingsService} from "../app/app";
import {clone} from "../helpers";

export default class SettingsEditor {
  constructor() {

    this.state = {changes: null, lastAction: {}};

    this.data = {settings: settingsService.state};
    this.changing = {};
  }

  async save() {

    this.state.changes = 'saving';
    await settingsService.save();
    this.state.changes = 'saved';
  }

  async commit(action)
  {
    await this.save();

    if(action.undo) {
      let undo = action.undo;
      action.undo = async () => {
        undo();
        await this.save();
        this.state.changes = 'undid';
      }
    }

    this.state.lastAction = action;
  }

  change(value, oldvalue)
  {
    if(!oldvalue) return;

    this.state.changes = 'dirty';
    settingsService.applyChanges();

    if(this.changing.internal) {
      this.changing.internal = false;
      return;
    }

    if(this.changing.timeout) clearTimeout(this.changing.timeout);

    const save_changes = () =>
    {
      let original = this.changing.original;
      this.changing.original = clone(this.data);

      this.commit({message: 'Settings updated.', fresh: true, icon: 'success',
        undo: () =>
        {
          this.changing.internal = true;
          Object.assign(this.data.settings, original.settings);
          this.changing.original = clone(this.data);
        }
      });

    };

    this.changing.timeout = setTimeout(save_changes, 1000);
  }

}<commit_msg>remove message popup on autosave<commit_after>import {settingsService} from "../app/app";
import {clone} from "../helpers";

export default class SettingsEditor {
  constructor() {

    this.state = {changes: null, lastAction: {}};

    this.data = {settings: settingsService.state};
    this.changing = {};
  }

  async save() {

    this.state.changes = 'saving';
    await settingsService.save();
    this.state.changes = 'saved';
  }

  async commit(action)
  {
    await this.save();

    if(action.undo) {
      let undo = action.undo;
      action.undo = async () => {
        undo();
        await this.save();
        this.state.changes = 'undid';
      }
    }

    this.state.lastAction = action;
  }

  change(value, oldvalue)
  {
    if(!oldvalue) return;

    this.state.changes = 'dirty';
    settingsService.applyChanges();

    if(this.changing.internal) {
      this.changing.internal = false;
      return;
    }

    if(this.changing.timeout) clearTimeout(this.changing.timeout);

    this.changing.timeout = setTimeout(() => this.save(), 1000);
  }

}
{'fraction_non_alphanumeric': 0.14874411302982732, 'fraction_numerical': 0.0031397174254317113, 'mean_word_length': 2.5110192837465566, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '2951392', 'n_tokens_mistral': 803, 'n_tokens_neox': 768, 'n_words': 150}