<commit_before>import _ from 'lodash'
import Vue from 'vue'
import Vuex from 'vuex'
import VueResource from 'vue-resource'
import BashEmulator from 'bash-emulator'
import * as utils from 'src/utils'
import * as getters from 'src/vuex/getters'

Vue.use(Vuex)
Vue.use(VueResource)

function saveLocalStorage (state) {
  window.localStorage.state = JSON.stringify(_.pick(state, [
    'currentLesson',
    'currentSection',
    'completedLessons',
    'solvedCurrentSection',
    'output',
    'emulator'
  ]))
}

const vuexState = JSON.parse(window.localStorage.state || '{}')

const emulator = window.emulator = BashEmulator(vuexState.emulator)

emulator.commands.clear = utils.clear
emulator.commands.yolo = utils.yolo

const lessons = require('../lessons')

const initialState = {
  currentLesson: 1,
  currentSection: 1,
  solvedCurrentSection: false,
  lessons: lessons,
  completedLessons: [],
  output: [],
  emulator: lessons[0].sections[0].emulator
}

const mutations = {
  START_SECTION (state, lessonNumber, sectionNumber) {
    console.log(`start lesson ${lessonNumber} and section ${sectionNumber}`)
    state.solvedCurrentSection = false
    state.currentLesson = lessonNumber
    state.currentSection = sectionNumber

    Object.assign(emulator.state, state.lessons[state.currentLesson - 1].sections[state.currentSection - 1].emulator)
    state.emulator = emulator.state
  },

  SEND_COMMAND (state, command) {
    state.output.push({type: 'INPUT', text: command})

    emulator
      .run(command)
      .then(result => {
        state.output.push({type: 'OUTPUT', text: result})
      }, err => {
        state.output.push({type: 'ERR', text: err})
      })
      .then(() => {
        state.emulator = emulator.state
        state.solvedCurrentSection = getters.getSolved(state)
        saveLocalStorage(state)
      })
  },
<commit_msg>Save to localStorage in the right moment<commit_after>import _ from 'lodash'
import Vue from 'vue'
import Vuex from 'vuex'
import VueResource from 'vue-resource'
import BashEmulator from 'bash-emulator'
import * as utils from 'src/utils'
import * as getters from 'src/vuex/getters'

Vue.use(Vuex)
Vue.use(VueResource)

function saveLocalStorage (state) {
  window.localStorage.state = JSON.stringify(_.pick(state, [
    'currentLesson',
    'currentSection',
    'completedLessons',
    'solvedCurrentSection',
    'output',
    'emulator'
  ]))
}

const vuexState = JSON.parse(window.localStorage.state || '{}')

const emulator = window.emulator = BashEmulator(vuexState.emulator)

emulator.commands.clear = utils.clear
emulator.commands.yolo = utils.yolo

const lessons = require('../lessons')

const initialState = {
  currentLesson: 1,
  currentSection: 1,
  solvedCurrentSection: false,
  lessons: lessons,
  completedLessons: [],
  output: [],
  emulator: lessons[0].sections[0].emulator
}

const mutations = {
  START_SECTION (state, lessonNumber, sectionNumber) {
    console.log(`start lesson ${lessonNumber} and section ${sectionNumber}`)
    state.solvedCurrentSection = false
    state.currentLesson = lessonNumber
    state.currentSection = sectionNumber

    saveLocalStorage(state)

    Object.assign(emulator.state, state.lessons[state.currentLesson - 1].sections[state.currentSection - 1].emulator)
    state.emulator = emulator.state
  },

  SEND_COMMAND (state, command) {
    state.output.push({type: 'INPUT', text: command})

    emulator
      .run(command)
      .then(result => {
        state.output.push({type: 'OUTPUT', text: result})
      }, err => {
        state.output.push({type: 'ERR', text: err})
      })
      .then(() => {
        state.emulator = emulator.state
        state.solvedCurrentSection = getters.getSolved(state)
        saveLocalStorage(state)
      })
  },

{'fraction_non_alphanumeric': 0.1286549707602339, 'fraction_numerical': 0.003189792663476874, 'mean_word_length': 3.781448538754765, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '5786269', 'n_tokens_mistral': 1217, 'n_tokens_neox': 1195, 'n_words': 245}