<commit_before>import LazyValue from "rebound/lazy-value";
// import { notify } from "rebound/runtime";

var hooks = {},
    helpers = {},
    partials = {},
    components = {},
    templates = {};


/*******************************
        Default helpers
********************************/

function __on(params, hash, options, env){
  var id = $(options.element).attr('data-event') || _.uniqueId('event'),
      i, callback,
      len = params.length,
      delegate = hash.selector || '[data-event='+id+']',
      data = hash.data && hash.data.isLazyValue && hash.data.value() || hash.data || options.context;

  // Set our element's data-event id
  $(options.element).attr('data-event', id);

  // Make sure we only attach once for each combination of delagate selector and callback
  for(i = 1; i<len; i++){
    callback = params[i];
    $(env.dom.document).on(params[0], delegate, data, function(event){
      return options.helpers.__callOnController(callback, event)
    })
    // this.outlet.off(eventName, delegate, this[params[i]]).on(eventName, delegate, data, this[params[i]]);
  }
}

function __action(params, hash, options, env){

}

function __length(params, hash, options, env){
    return params[0] && params[0].length || 0;
}

// Attribute helper handles binding data to dom attributes
function __attribute(params, hash, options, env) {
  var checkboxChange,
      type = options.element.getAttribute("type"),
      attr;

  // If is a text input element's value prop with only one variable, wire default events
  if(options.element.tagName === 'INPUT' && (
         type === 'text'
      || type === 'email'
      || type === 'password'
      || type === 'search'
      || type === 'url'
      || type === 'tel' ) && params[0] === 'value' && !options.params[1].children ){

    // If our special input events have not been bound yet, bind them and set flag
    if(!options.lazyValue.eventsBound){

      // If a submit action has been set
      attr = $(options.element).attr('rebound-action')
      $(options.element).on('input propertychange', options.context, function(event){
        options.context.set(options.params[1].path, this.value);
      });
      $(options.element).on('keyup', options.context, function(event){
        if(event.keyCode == 13 && attr){
          options.helpers.__callOnController(attr, event);
        }
      });

      options.lazyValue.eventsBound = true;
    }

    return options.context.get(options.params[1].path);
  }

  if(options.element.tagName === 'INPUT' && options.element.getAttribute("type") === 'checkbox' && params[0] === 'checked' && !options.params[1].children ){

    // If our special input events have not been bound yet, bind them and set flag
    if(!options.lazyValue.eventsBound){
      $(options.element).on('change', function(){
        options.context.set(options.params[1].path, this.checked);
      });

      options.lazyValue.eventsBound = true;
    }

    return options.element.checked = (params[1]) ? true : undefined;
  }

  return params[1];
}

function __concat(params, hash, options, env) {
  var value = "";
  for (var i = 0, l = params.length; i < l; i++) {
    value += params[i];
  }
  return value;
}

function __if(params, hash, options, env){

  var condition = params[0];

  if(Backbone && condition.isModel){
    condition = true;
  }

  // If our condition is an array, handle properly
  if(_.isArray(condition) || Backbone && condition.isCollection){
    condition = condition.length ? true : false;
  }

  // If more than one param, this is not a block helper. Eval as such.
  if(params.length > 1)
    return (condition) ? params[1] : ( params[2] || '');

  // Check our cache. If the value hasn't actually changed, don't evaluate. Important for re-rendering of #each helpers.
  if(options.placeholder.__ifCache == condition) return undefined;

  options.placeholder.__ifCache = condition;

  // Render the apropreate block statement
  if(condition && typeof options.render === 'function'){
    return options.render(options.context, options);
  }
  else if(!condition && typeof options.inverse === 'function'){
    return options.inverse(options.context, options);
  }

  return '';
}

function __unless(params, hash, options, env){
  var condition = params[0];

  if(Backbone && condition.isModel){
    condition = true;
  }

  // If our condition is an array, handle properly
  if(_.isArray(condition) || Backbone && condition.isCollection){
    condition = condition.length ? true : false;
  }

  // If more than one param, this is not a block helper. Eval as such.
  if(params.length > 1)
    return (condition) ? params[1] : ( params[2] || '');

  // Check our cache. If the value hasn't actually changed, don't evaluate. Important for re-rendering of #each helpers.
  if(options.placeholder.__unlessCache == condition) return undefined;

  options.placeholder.__unlessCache = condition;

  // Render the apropreate block statement
  if(!condition && typeof options.render === 'function'){
    return options.render(options.context, options);
  }
  else if(condition && typeof options.inverse === 'function'){
    return options.inverse(options.context, options);
  }

  return '';
}

function __each(params, hash, options, env){
  var value = params[0];

  if(!value) return;

  if(value.isCollection){
    value = value.models;
  }

  // Remove elements at indicies passed to us in the collection's __removedIndex array
  if(_.isArray(value.__removedIndex) && value.__removedIndex.length && options.placeholder.morphs){
    // For each removed indes, in decending order so we dont mess up the dom for later indicies, destroy its morph element
    _.each(_.sortBy(value.__removedIndex, function(num){return num;}).reverse(), function(index){
      options.placeholder.morphs[index].destroy();
    })
    // Leave our removed index array clean for the next call
    value.__removedIndex.length = 0;
  }

  value.__indexed = false;

  _.each(value, function(obj, key, list){

    // Even if rendered already, update each element's index in case of order changes or element removals
    obj.set({'@index': key});
<commit_msg>Added key, first and last to each scope<commit_after>import LazyValue from "rebound/lazy-value";
// import { notify } from "rebound/runtime";

var hooks = {},
    helpers = {},
    partials = {},
    components = {},
    templates = {};


/*******************************
        Default helpers
********************************/

function __on(params, hash, options, env){
  var id = $(options.element).attr('data-event') || _.uniqueId('event'),
      i, callback,
      len = params.length,
      delegate = hash.selector || '[data-event='+id+']',
      data = hash.data && hash.data.isLazyValue && hash.data.value() || hash.data || options.context;

  // Set our element's data-event id
  $(options.element).attr('data-event', id);

  // Make sure we only attach once for each combination of delagate selector and callback
  for(i = 1; i<len; i++){
    callback = params[i];
    $(env.dom.document).on(params[0], delegate, data, function(event){
      return options.helpers.__callOnController(callback, event)
    })
    // this.outlet.off(eventName, delegate, this[params[i]]).on(eventName, delegate, data, this[params[i]]);
  }
}

function __action(params, hash, options, env){

}

function __length(params, hash, options, env){
    return params[0] && params[0].length || 0;
}

// Attribute helper handles binding data to dom attributes
function __attribute(params, hash, options, env) {
  var checkboxChange,
      type = options.element.getAttribute("type"),
      attr;

  // If is a text input element's value prop with only one variable, wire default events
  if(options.element.tagName === 'INPUT' && (
         type === 'text'
      || type === 'email'
      || type === 'password'
      || type === 'search'
      || type === 'url'
      || type === 'tel' ) && params[0] === 'value' && !options.params[1].children ){

    // If our special input events have not been bound yet, bind them and set flag
    if(!options.lazyValue.eventsBound){

      // If a submit action has been set
      attr = $(options.element).attr('rebound-action')
      $(options.element).on('input propertychange', options.context, function(event){
        options.context.set(options.params[1].path, this.value);
      });
      $(options.element).on('keyup', options.context, function(event){
        if(event.keyCode == 13 && attr){
          options.helpers.__callOnController(attr, event);
        }
      });

      options.lazyValue.eventsBound = true;
    }

    return options.context.get(options.params[1].path);
  }

  if(options.element.tagName === 'INPUT' && options.element.getAttribute("type") === 'checkbox' && params[0] === 'checked' && !options.params[1].children ){

    // If our special input events have not been bound yet, bind them and set flag
    if(!options.lazyValue.eventsBound){
      $(options.element).on('change', function(){
        options.context.set(options.params[1].path, this.checked);
      });

      options.lazyValue.eventsBound = true;
    }

    return options.element.checked = (params[1]) ? true : undefined;
  }

  return params[1];
}

function __concat(params, hash, options, env) {
  var value = "";
  for (var i = 0, l = params.length; i < l; i++) {
    value += params[i];
  }
  return value;
}

function __if(params, hash, options, env){

  var condition = params[0];

  if(Backbone && condition.isModel){
    condition = true;
  }

  // If our condition is an array, handle properly
  if(_.isArray(condition) || Backbone && condition.isCollection){
    condition = condition.length ? true : false;
  }

  // If more than one param, this is not a block helper. Eval as such.
  if(params.length > 1)
    return (condition) ? params[1] : ( params[2] || '');

  // Check our cache. If the value hasn't actually changed, don't evaluate. Important for re-rendering of #each helpers.
  if(options.placeholder.__ifCache == condition) return undefined;

  options.placeholder.__ifCache = condition;

  // Render the apropreate block statement
  if(condition && typeof options.render === 'function'){
    return options.render(options.context, options);
  }
  else if(!condition && typeof options.inverse === 'function'){
    return options.inverse(options.context, options);
  }

  return '';
}

function __unless(params, hash, options, env){
  var condition = params[0];

  if(Backbone && condition.isModel){
    condition = true;
  }

  // If our condition is an array, handle properly
  if(_.isArray(condition) || Backbone && condition.isCollection){
    condition = condition.length ? true : false;
  }

  // If more than one param, this is not a block helper. Eval as such.
  if(params.length > 1)
    return (condition) ? params[1] : ( params[2] || '');

  // Check our cache. If the value hasn't actually changed, don't evaluate. Important for re-rendering of #each helpers.
  if(options.placeholder.__unlessCache == condition) return undefined;

  options.placeholder.__unlessCache = condition;

  // Render the apropreate block statement
  if(!condition && typeof options.render === 'function'){
    return options.render(options.context, options);
  }
  else if(condition && typeof options.inverse === 'function'){
    return options.inverse(options.context, options);
  }

  return '';
}

function __each(params, hash, options, env){
  var value = params[0],
      length = params[0].length;

  if(!value) return;

  if(value.isCollection){
    value = value.models;
  }

  // Remove elements at indicies passed to us in the collection's __removedIndex array
  if(_.isArray(value.__removedIndex) && value.__removedIndex.length && options.placeholder.morphs){
    // For each removed indes, in decending order so we dont mess up the dom for later indicies, destroy its morph element
    _.each(_.sortBy(value.__removedIndex, function(num){return num;}).reverse(), function(index){
      options.placeholder.morphs[index].destroy();
    })
    // Leave our removed index array clean for the next call
    value.__removedIndex.length = 0;
  }

  value.__indexed = false;

  _.each(value, function(obj, key, list){

    // Even if rendered already, update each element's index, key, first and last in case of order changes or element removals
    if(_.isArray(value)){
      obj.set({'@index': key, '@first': (key == 0), '@last': (key == length-1)});
    }
    if(!_.isArray(value) && _.isObject(value))
      obj.set({'@key' : key})


{'fraction_non_alphanumeric': 0.15438708646316127, 'fraction_numerical': 0.004554898513664696, 'mean_word_length': 3.444247159090909, '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': '2840749', 'n_tokens_mistral': 3715, 'n_tokens_neox': 3616, 'n_words': 1050}