<commit_before>import scripts from './scripts';
import types from '../blockTypes';
import testing from './testing';
import consts from '../../constants';
import events from '../../events';

var blocksWithCode = {};

export default {
  init() {
    events.on(consts.events.RELOAD_CODE, position => {
      console.log(position, typeof position);
      if(this.hasCode(position)) {
        let blockTypeId = this.getBlockTypeId(position);
        scripts.createInstance(position, blockTypeId);
        console.log(`Code of block of type ${blockTypeId} at ${position} reset!`);
      }
    });
  },
  getCode(position) {
    let blockType = types.getById(blocksWithCode[position]);
    let code = scripts.getCode(blockType.id);

    return {
      blockType,
      code
    };
  },
  getBlockTypeId(position){
    return blocksWithCode[position];
  },
  hasCode(position) {
    return !!blocksWithCode[position];
  },
  storeCode(position, id) {
    blocksWithCode[position] = id;
    scripts.createInstance(position, id);

    // if we had existing testing code (brought from local storage), activate now
    if(testing.hasTestingCode(position)) {
      let blockType = types.getById(id);
      testing.activateTestingCode(position, blockType);
    }
  },
  removeCode(position) {
    delete blocksWithCode[position];
    scripts.removeInstance(position);
  }<commit_msg>adding comment to fix bug later<commit_after>import scripts from './scripts';
import types from '../blockTypes';
import testing from './testing';
import consts from '../../constants';
import events from '../../events';

var blocksWithCode = {};

export default {
  init() {
    events.on(consts.events.RELOAD_CODE, position => {
      console.log(position, typeof position);
      if(this.hasCode(position)) {
        let blockTypeId = this.getBlockTypeId(position);
        scripts.createInstance(position, blockTypeId);
        console.log(`Code of block of type ${blockTypeId} at ${position} reset!`);
      }
    });
  },
  getCode(position) {
    let blockType = types.getById(blocksWithCode[position]);
    let code = scripts.getCode(blockType.id);

    return {
      blockType,
      code
    };
  },
  getBlockTypeId(position){
    return blocksWithCode[position];
  },
  hasCode(position) {
    return !!blocksWithCode[position];
  },
  storeCode(position, id) {
    blocksWithCode[position] = id;
    scripts.createInstance(position, id);

    // if we had existing testing code (brought from local storage), activate now
    // FIXME this brings problem when saving code that was being tested, because testing code is installed. FIX
    if(testing.hasTestingCode(position)) {
      let blockType = types.getById(id);
      testing.activateTestingCode(position, blockType);
    }
  },
  removeCode(position) {
    delete blocksWithCode[position];
    scripts.removeInstance(position);
  }
{'fraction_non_alphanumeric': 0.12761506276150628, 'fraction_numerical': 0.0, 'mean_word_length': 3.434312210200927, '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': '4414567', 'n_tokens_mistral': 810, 'n_tokens_neox': 813, 'n_words': 200}