<commit_before>define(["backbone", "jquery", "underscore", "selectable", "config"],
       function(B, $, _, SelectableCollection, config) {
           var RegionModel = B.Model.extend({
               loadShape: function() {
                   var shape = this.get("shape");

                   if (shape)
                       return $.Deferred().resolve(shape);

                   var self = this;
                   return $.getJSON(this.get("source"))
                       .done(function(shape) {
                           self.set("shape", shape);
                           self.trigger("regionLoaded", shape);
                       });

               }
           });

           var regions = _.map(config.regions, function(region) {
               return new RegionModel(region);
           });

           var RegionCollection = SelectableCollection.extend({
               selection: ["somerville"],

               model: RegionModel,

               hashParam: "f.region"
           });

           return new RegionCollection(regions);
       });<commit_msg>Reuse Deferred when reloading region shape<commit_after>define(["backbone", "jquery", "underscore", "selectable", "config"],
       function(B, $, _, SelectableCollection, config) {
           var RegionModel = B.Model.extend({
               loadShape: function() {
                   var shape = this.get("shape");

                   if (shape)
                       return $.Deferred().resolve(shape);

                   if (!this._fetchingShape) {

                   var self = this;
                   this._fetchingShape =
                           $.getJSON(this.get("source"))
                           .done(function(shape) {
                               self.set("shape", shape);
                               self.trigger("regionLoaded", shape);
                               self._fetchingShape = null;
                           });
                   }
                   return this._fetchingShape;
               }
           });

           var regions = _.map(config.regions, function(region) {
               return new RegionModel(region);
           });

           var RegionCollection = SelectableCollection.extend({
               selection: ["somerville"],

               model: RegionModel,

               hashParam: "f.region"
           });

           return new RegionCollection(regions);
       });
{'fraction_non_alphanumeric': 0.11358942585708386, 'fraction_numerical': 0.0, 'mean_word_length': 1.232258064516129, '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': '2352754', 'n_tokens_mistral': 560, 'n_tokens_neox': 520, 'n_words': 109}