<commit_before>/*!
    Copyright (C) 2013 Google Inc., authors, and contributors <see AUTHORS file>
    Licensed under http://www.apache.org/licenses/LICENSE-2.0 <see LICENSE file>
    Created By: <EMAIL>
    Maintained By: <EMAIL>
*/

;(function(GGRC, can) {

  /*  GGRC.ListLoaders
   *
   *  - Generates and manages lists of related objects, pairing each instance
   *      with the one or more "mappings" -- join tables, direct relationships,
   *      etc -- which cause it to be present in the list.
   *
   *  Terminology:
   *    - "mappings" -- a list of "result" objects defining the path between
   *        the root object and the paired instance; can also be the boolean
   *        literal "true", to denote the "root" instance
   *    - "result" -- the (instance, mappings) pairs
   *    - "binding" -- the pairing between a list of results and the "root"
   *        instance for that list
   *        e.g., for each item in binding.list, if you follow the chain of
   *          mappings, you will eventually find
   *            ``{ instance: binding.instance, mappings: true }``
   */

  /*  GGRC.ListLoaders.MappingResult
   *
   *  - `instance`: The resulting item itself
   *  - `mappings`: Essentially, the reason(s) the instance appears in the
   *      list.  This may be an instance of can.Model or a pair containing
   *      (binding, result) in the case of a chained ListLoader.
   *
   *  For FilteredListLoader, the mappings are (`result`, `binding`), where
   *    `binding` is the binding in which the result appears, and thus,
   *    `binding.loader` contains information about the filter.
   *    `binding.instance`, then, is the instance on which the original,
   *    unfiltered list is specified.
   *  For CrossListLoader, the mappings are (`result`, `binding`), where
   *    `binding` is the "remote binding" which 
   */
  can.Construct("GGRC.ListLoaders.MappingResult", {
  }, {
      init: function(instance, mappings, binding) {
        if (!mappings) {
          // Assume item was passed in as an object
          mappings = instance.mappings;
          binding = instance.binding;
          instance = instance.instance;
        }

        this.instance = instance;
        this.mappings = this._make_mappings(mappings);
        this.binding = binding;
      }

    //  `_make_mappings`
    //  - Ensures that every instance in `mappings` is an instance of
    //    `MappingResult`.
    , _make_mappings: function(mappings) {
        var i
          , mapping
          ;

        if (!mappings)
          mappings = [];

        for (i=0; i<mappings.length; i++) {
          mapping = mappings[i];
          if (!(mapping instanceof GGRC.ListLoaders.MappingResult))
            mapping = new GGRC.ListLoaders.MappingResult(mapping);
          mappings[i] = mapping;
        }

        return mappings;
      }

    //  `observe_trigger`, `watch_observe_trigger`, `trigger_observe_trigger`
    //  - These exist solely to support dynamic updating of `*_compute`.
    //    Basically, these fake dependencies for those computes so each is
    //    updated any time a mapping is inserted or removed beyond a
    //    "virtual" level, which would otherwise obscure changes in the
    //    "first-level mappings" which both `bindings_compute` and
    //    `mappings_compute` depend on.
    , observe_trigger: function() {
        if (!this._observe_trigger)
          this._observe_trigger = new can.Observe({ change_count: 1 });
        return this._observe_trigger;
      }

    , watch_observe_trigger: function() {
        this.observe_trigger().attr("change_count");
        can.each(this.mappings, function(mapping) {
          if (mapping.watch_observe_trigger)
            mapping.watch_observe_trigger();
        });
      }

    , trigger_observe_trigger: function() {
        var observe_trigger = this.observe_trigger();
        observe_trigger.attr("change_count", observe_trigger.change_count + 1);
      }

    //  `insert_mapping` and `remove_mapping`
    //  - These exist solely to trigger an `observe_trigger` change event
    , insert_mapping: function(mapping) {
        this.mappings.push(mapping);
        // Trigger change event
        this.trigger_observe_trigger();
      }

    , remove_mapping: function(mapping) {
        var ret;
        mapping_index = this.mappings.indexOf(mapping);
        if (mapping_index > -1) {
          ret = this.mappings.splice(mapping_index, 1);
          //  Trigger change event
          this.trigger_observe_trigger();
          return ret;
        }
      }

    //  `get_bindings`, `bindings_compute`, `get_bindings_compute`
    //  - Returns a list of the `ListBinding` instances which are the source
    //    of "first-level mappings".
    , get_bindings: function() {
        var self = this
          , bindings = []
          ;

        this.walk_instances(function(instance, result, depth) {
          if (depth === 1)
            bindings.push(result.binding);
        });
        return bindings;
      }

    , bindings_compute: function() {
        if (!this._bindings_compute)
          this._bindings_compute = this.get_bindings_compute();
        return this._bindings_compute;
      }

    , get_bindings_compute: function() {
        var self = this;

        return can.compute(function() {
          // Unnecessarily access observe_trigger to be able to trigger change
          self.watch_observe_trigger();
          return self.get_bindings();
        });
      }

    //  `get_mappings`, `mappings_compute`, and `get_mappings_compute`
    //  - Returns a list of first-level mapping instances, even if they're
    //    several levels down due to virtual mappers like Multi or Cross
    //  - "First-level mappings" are the objects whose existence causes the
    //    `binding.instance` to be in the current `binding.list`.  (E.g.,
    //    if any of the "first-level mappings" exist, the instance will
    //    appear in the list.
    , get_mappings: function() {
        var self = this
          , mappings = []
          ;

        this.walk_instances(function(instance, result, depth) {
          if (depth == 1) {
            if (instance === true)
              mappings.push(result.binding.instance);
            else
              mappings.push(instance);
          }
        });
        return mappings;
      }

    , mappings_compute: function() {
        if (!this._mappings_compute)
          this._mappings_compute = this.get_mappings_compute();
        return this._mappings_compute;
      }

    , get_mappings_compute: function() {
        var self = this;

        return can.compute(function() {
          // Unnecessarily access _observe_trigger to be able to trigger change
          self.watch_observe_trigger();<commit_msg>Fix `get_mappings` to return the correct Direct mappings<commit_after>/*!
    Copyright (C) 2013 Google Inc., authors, and contributors <see AUTHORS file>
    Licensed under http://www.apache.org/licenses/LICENSE-2.0 <see LICENSE file>
    Created By: <EMAIL>
    Maintained By: <EMAIL>
*/

;(function(GGRC, can) {

  /*  GGRC.ListLoaders
   *
   *  - Generates and manages lists of related objects, pairing each instance
   *      with the one or more "mappings" -- join tables, direct relationships,
   *      etc -- which cause it to be present in the list.
   *
   *  Terminology:
   *    - "mappings" -- a list of "result" objects defining the path between
   *        the root object and the paired instance; can also be the boolean
   *        literal "true", to denote the "root" instance
   *    - "result" -- the (instance, mappings) pairs
   *    - "binding" -- the pairing between a list of results and the "root"
   *        instance for that list
   *        e.g., for each item in binding.list, if you follow the chain of
   *          mappings, you will eventually find
   *            ``{ instance: binding.instance, mappings: true }``
   */

  /*  GGRC.ListLoaders.MappingResult
   *
   *  - `instance`: The resulting item itself
   *  - `mappings`: Essentially, the reason(s) the instance appears in the
   *      list.  This may be an instance of can.Model or a pair containing
   *      (binding, result) in the case of a chained ListLoader.
   *
   *  For FilteredListLoader, the mappings are (`result`, `binding`), where
   *    `binding` is the binding in which the result appears, and thus,
   *    `binding.loader` contains information about the filter.
   *    `binding.instance`, then, is the instance on which the original,
   *    unfiltered list is specified.
   *  For CrossListLoader, the mappings are (`result`, `binding`), where
   *    `binding` is the "remote binding" which 
   */
  can.Construct("GGRC.ListLoaders.MappingResult", {
  }, {
      init: function(instance, mappings, binding) {
        if (!mappings) {
          // Assume item was passed in as an object
          mappings = instance.mappings;
          binding = instance.binding;
          instance = instance.instance;
        }

        this.instance = instance;
        this.mappings = this._make_mappings(mappings);
        this.binding = binding;
      }

    //  `_make_mappings`
    //  - Ensures that every instance in `mappings` is an instance of
    //    `MappingResult`.
    , _make_mappings: function(mappings) {
        var i
          , mapping
          ;

        if (!mappings)
          mappings = [];

        for (i=0; i<mappings.length; i++) {
          mapping = mappings[i];
          if (!(mapping instanceof GGRC.ListLoaders.MappingResult))
            mapping = new GGRC.ListLoaders.MappingResult(mapping);
          mappings[i] = mapping;
        }

        return mappings;
      }

    //  `observe_trigger`, `watch_observe_trigger`, `trigger_observe_trigger`
    //  - These exist solely to support dynamic updating of `*_compute`.
    //    Basically, these fake dependencies for those computes so each is
    //    updated any time a mapping is inserted or removed beyond a
    //    "virtual" level, which would otherwise obscure changes in the
    //    "first-level mappings" which both `bindings_compute` and
    //    `mappings_compute` depend on.
    , observe_trigger: function() {
        if (!this._observe_trigger)
          this._observe_trigger = new can.Observe({ change_count: 1 });
        return this._observe_trigger;
      }

    , watch_observe_trigger: function() {
        this.observe_trigger().attr("change_count");
        can.each(this.mappings, function(mapping) {
          if (mapping.watch_observe_trigger)
            mapping.watch_observe_trigger();
        });
      }

    , trigger_observe_trigger: function() {
        var observe_trigger = this.observe_trigger();
        observe_trigger.attr("change_count", observe_trigger.change_count + 1);
      }

    //  `insert_mapping` and `remove_mapping`
    //  - These exist solely to trigger an `observe_trigger` change event
    , insert_mapping: function(mapping) {
        this.mappings.push(mapping);
        // Trigger change event
        this.trigger_observe_trigger();
      }

    , remove_mapping: function(mapping) {
        var ret;
        mapping_index = this.mappings.indexOf(mapping);
        if (mapping_index > -1) {
          ret = this.mappings.splice(mapping_index, 1);
          //  Trigger change event
          this.trigger_observe_trigger();
          return ret;
        }
      }

    //  `get_bindings`, `bindings_compute`, `get_bindings_compute`
    //  - Returns a list of the `ListBinding` instances which are the source
    //    of "first-level mappings".
    , get_bindings: function() {
        var self = this
          , bindings = []
          ;

        this.walk_instances(function(instance, result, depth) {
          if (depth === 1)
            bindings.push(result.binding);
        });
        return bindings;
      }

    , bindings_compute: function() {
        if (!this._bindings_compute)
          this._bindings_compute = this.get_bindings_compute();
        return this._bindings_compute;
      }

    , get_bindings_compute: function() {
        var self = this;

        return can.compute(function() {
          // Unnecessarily access observe_trigger to be able to trigger change
          self.watch_observe_trigger();
          return self.get_bindings();
        });
      }

    //  `get_mappings`, `mappings_compute`, and `get_mappings_compute`
    //  - Returns a list of first-level mapping instances, even if they're
    //    several levels down due to virtual mappers like Multi or Cross
    //  - "First-level mappings" are the objects whose existence causes the
    //    `binding.instance` to be in the current `binding.list`.  (E.g.,
    //    if any of the "first-level mappings" exist, the instance will
    //    appear in the list.
    , get_mappings: function() {
        var self = this
          , mappings = []
          ;

        this.walk_instances(function(instance, result, depth) {
          if (depth == 1) {
            if (instance === true)
              mappings.push(self.instance);
            else
              mappings.push(instance);
          }
        });
        return mappings;
      }

    , mappings_compute: function() {
        if (!this._mappings_compute)
          this._mappings_compute = this.get_mappings_compute();
        return this._mappings_compute;
      }

    , get_mappings_compute: function() {
        var self = this;

        return can.compute(function() {
          // Unnecessarily access _observe_trigger to be able to trigger change
          self.watch_observe_trigger();
{'fraction_non_alphanumeric': 0.10175593270149144, 'fraction_numerical': 0.0019102196752626551, 'mean_word_length': 2.2020701011526698, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5386792', 'n_tokens_mistral': 3888, 'n_tokens_neox': 3764, 'n_words': 1116}