<commit_before>'use strict';

var sublevelIndexes = require('./sublevel-indexes')

function noopValidate () { return true }

/**
 * Sets up the view showing the indexes and the editor itself.
 * Additionally it hooks up events to:
 *  - show relevant data when item from indexes is selected
 *  - save edited data when save button is clicked
 * 
 * @name exports
 * @function
 * @param db {Level} database
 * @param events {EventEmitter} into which it will emit events
 * @param opts {Object} with the following properties:
 *    - validate {Function} (optional) called with the entry to be saved 
 *      - return false if entry is invalid and shouldn't be saved
 *      - return true if entry is valid and can be saved
 *    - dataPrefix {String} the prefix of the sublevel that holds the actual data to show in the data editor
 *    - options used to index the sublevels, i.e. isIndex {Function} -- see more in sublevel-indexes.js
 * @param editors {Object} with the following properties:
 *    - indexes {DOMElement} holding the indexes view
 *    - editor: {DOMElement} holding the data editor
 * @param containers {Object} containing other important 
 *    - saveButton: {DOMElement} that represents the button that the user clicks in order to save edited data 
 */
var go = module.exports = function (db, events, opts, editors, containers) {
  var data = db.sublevels[opts.dataPrefix];
  var validate = opts.validate || noopValidate;
  var loaded;

  function loadData(key, suppressEvent, cb) {
    data.get(key, function (err, val) {
      if (err) {
        if (cb) cb(err);
        return events.emit('error', err);
      }

      loaded = { key: key, value: val };
      editors.editor.set(val);

      if (!suppressEvent) events.emit('entry-loaded', loaded);
      if (cb) cb();
    });
  }

  sublevelIndexes(db.sublevels, opts, function (err, indexes) {<commit_msg>emitting entry-loading before it gets added to the editor<commit_after>'use strict';

var sublevelIndexes = require('./sublevel-indexes')

function noopValidate () { return true }

/**
 * Sets up the view showing the indexes and the editor itself.
 * Additionally it hooks up events to:
 *  - show relevant data when item from indexes is selected
 *  - save edited data when save button is clicked
 * 
 * @name exports
 * @function
 * @param db {Level} database
 * @param events {EventEmitter} into which it will emit events
 * @param opts {Object} with the following properties:
 *    - validate {Function} (optional) called with the entry to be saved 
 *      - return false if entry is invalid and shouldn't be saved
 *      - return true if entry is valid and can be saved
 *    - dataPrefix {String} the prefix of the sublevel that holds the actual data to show in the data editor
 *    - options used to index the sublevels, i.e. isIndex {Function} -- see more in sublevel-indexes.js
 * @param editors {Object} with the following properties:
 *    - indexes {DOMElement} holding the indexes view
 *    - editor: {DOMElement} holding the data editor
 * @param containers {Object} containing other important 
 *    - saveButton: {DOMElement} that represents the button that the user clicks in order to save edited data 
 */
var go = module.exports = function (db, events, opts, editors, containers) {
  var data = db.sublevels[opts.dataPrefix];
  var validate = opts.validate || noopValidate;
  var loaded;

  function loadData(key, suppressEvent, cb) {
    data.get(key, function (err, val) {
      if (err) {
        if (cb) cb(err);
        return events.emit('error', err);
      }

      loaded = { key: key, value: val };
      if (!suppressEvent) events.emit('entry-loading', loaded);

      editors.editor.set(val);

      if (!suppressEvent) events.emit('entry-loaded', loaded);
      if (cb) cb();
    });
  }

  sublevelIndexes(db.sublevels, opts, function (err, indexes) {
{'fraction_non_alphanumeric': 0.10033617791569692, 'fraction_numerical': 0.0, 'mean_word_length': 3.293007769145394, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2541762', 'n_tokens_mistral': 1099, 'n_tokens_neox': 1056, 'n_words': 452}