<commit_before>/*
Simple List Primary arguments

propertyName {string} name of the property that is considered "primary"
badge {string} string to put in the badge. defaults to property name
 */

var _ = require('lodash'),
  dom = require('../services/dom');

module.exports = function (result, args) {
  var prop = args.propertyName,
    badge = args.badge || prop,
    itemEls = dom.findAll(result.el, '.simple-list-item');

  // add doubleclick event to all list items
  _.forEach(itemEls, function (itemEl) {
    itemEl.setAttribute('rv-on-dblclick', 'setPrimary');
    itemEl.setAttribute('rv-class-primary', 'item.' + prop);

    // add primary badge
    itemEl.appendChild(dom.create('<div class="badge">' + badge + '</div>'));
    return itemEl;
  });

  function unsetAll(items) {
    return items.map(function (item) {
      item[prop] = false;
      return item;
    });
  }

  function setPrimary(bindings) {
    var item = bindings.item,
      data = bindings.data;

    unsetAll(data);
    item[prop] = true;
  }

  // double clicking unsets all items and sets the current item as primary,
  // using whatever property name you passed through as an argument
  result.bindings.setPrimary = function (e, bindings) {
    setPrimary(bindings);
  };

  return result;
};<commit_msg>unset primary item<commit_after>/*
Simple List Primary arguments

propertyName {string} name of the property that is considered "primary"
badge {string} string to put in the badge. defaults to property name
 */

var _ = require('lodash'),
  dom = require('../services/dom');

module.exports = function (result, args) {
  var prop = args.propertyName,
    badge = args.badge || prop,
    itemEls = dom.findAll(result.el, '.simple-list-item');

  // add doubleclick event to all list items
  _.forEach(itemEls, function (itemEl) {
    itemEl.setAttribute('rv-on-dblclick', 'togglePrimary');
    itemEl.setAttribute('rv-class-primary', 'item.' + prop);

    // add primary badge
    itemEl.appendChild(dom.create('<div class="badge">' + badge + '</div>'));
    return itemEl;
  });

  function unsetAll(items) {
    return items.map(function (item) {
      item[prop] = false;
      return item;
    });
  }

  function togglePrimary(bindings) {
    var item = bindings.item,
      data = bindings.data,
      isPrimary = item[prop]; // get this before unsetting everything

    unsetAll(data);
    if (!isPrimary) {
      item[prop] = true;
    }
  }

  // double clicking unsets all items and sets the current item as primary,
  // using whatever property name you passed through as an argument
  result.bindings.togglePrimary = function (e, bindings) {
    togglePrimary(bindings);
  };

  return result;
};
{'fraction_non_alphanumeric': 0.12940304041527623, 'fraction_numerical': 0.0, 'mean_word_length': 3.3099041533546325, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '4490094', 'n_tokens_mistral': 827, 'n_tokens_neox': 806, 'n_words': 243}