<commit_before>define([
    'jquery',
    'underscore',
    'backbone',
    'config',
    'utils',
    'text!templates/homepage.html',
    'lib/color-gradient/color-gradient'
], function($, _, Backbone, config, utils, templateHtml, ColorGradient) {
    "use strict";

    var MapViewBase = Backbone.View.extend({

        initialize: function(options) 
        {
            this.layers = [];
            this.vent = options.vent;

            if (options.visibleMapArea) {
                this.initialVisibleMapArea = options.visibleMapArea;
            }
        },

        renderMap: function(viewBase, viewStyle) 
        {
            if (this.initialVisibleMapArea) {
                this.visibleAreaChangedInitially = true;
                this.setVisibleMapArea(this.initialVisibleMapArea);
            }
            return this;
        },

        /**
        * Required to be implemented by descendants.
        */
        getVisibleMapArea: function()
        {
            return {
                bounds: null,
                zoom: null
            };
        },
        
        /**
        * Required to be implemented by descendants.
        */
        setVisibleMapArea: function(to) {
        },

        visibleAreaChanged: function(visibleMapArea)
        {
            var self = this;
            if (!this.visibleAreaChangedInitially) {
                // TODO move to app
                app.navigate(app.genMapURIForVisibleArea(visibleMapArea));
            }
            this.visibleAreaChangedInitially = false;
            console.log('visibleAreaChanged');
            this.trigger('visibleAreaChanged');
        },

        /**
        * Map layer management
        */

        attachLayer: function(model)
        {
            this.layers.push(model);
            this.listenTo(model, 'toggle:enabled', this.layerToggled);
            this.listenTo(model, 'change', this.layerChanged);
            this.listenTo(model, 'toggle:colorScheme', this.layerChanged);
            var c = model.featureCollection;
            this.listenTo(c, {
                reset: this.featureReset
            });
            this.listenTo(c, 'add', this.featureAdd);
            this.listenTo(c, 'remove', this.featureRemove);
            this.listenTo(c, 'change', this.featureChange);
            this.listenTo(model, 'destroy', this.destroyLayer);

            this.featureReset(model.featureCollection);
        },

        layerToggled: function(model)
        {
        },

        layerChanged: function(model)
        {
        },

        drawLayer: function(model)
        {
        },

        destroyLayer: function(model)
        {
            this.layers.splice(this.layers.indexOf(model), 1);
            this.stopListening(model);
            this.stopListening(model.featureCollection);
        },

        /**
        * Map feature collection events
        */

        featureReset: function(collection, options) 
        {   
            var self = this;
            collection.each(function(model) {
                self.featureAdd(model, collection, options);
            });
            self.drawLayer(collection.mapLayer);
        },

        featureAdd: function(model, collection, options)  
        {
        },

        featureRemove: function(model, collection, options) 
        {
        },

        featureChange: function(model, options)
        {
        },

    });

    return MapViewBase;
});
<commit_msg>Queue and cancel reloading/redrawing for better efficiency<commit_after>define([
    'jquery',
    'underscore',
    'backbone',
    'config',
    'utils',
    'text!templates/homepage.html',
    'lib/color-gradient/color-gradient'
], function($, _, Backbone, config, utils, templateHtml, ColorGradient) {
    "use strict";

    var MapViewBase = Backbone.View.extend({

        initialize: function(options) 
        {
            this.layers = [];
            this.redrawQueue = [];
            this.vent = options.vent;

            if (options.visibleMapArea) {
                this.initialVisibleMapArea = options.visibleMapArea;
            }
        },

        renderMap: function(viewBase, viewStyle) 
        {
            if (this.initialVisibleMapArea) {
                this.visibleAreaChangedInitially = true;
                this.setVisibleMapArea(this.initialVisibleMapArea);
            }
            return this;
        },

        /**
        * Required to be implemented by descendants.
        */
        getVisibleMapArea: function()
        {
            return {
                bounds: null,
                zoom: null
            };
        },
        
        /**
        * Required to be implemented by descendants.
        */
        setVisibleMapArea: function(to) {
        },

        visibleAreaChanged: function(visibleMapArea)
        {
            var self = this;
            if (!this.visibleAreaChangedInitially) {
                // TODO move to app
                app.navigate(app.genMapURIForVisibleArea(visibleMapArea));
            }
            this.visibleAreaChangedInitially = false;

            self.redrawQueue.push(setTimeout(function() {
                console.log('visibleAreaChanged');
                self.trigger('visibleAreaChanged');
            }, 250));
            for (var i = self.redrawQueue.length; i > 1; i--) {
                clearTimeout(self.redrawQueue.shift());
            }
        },

        /**
        * Map layer management
        */

        attachLayer: function(model)
        {
            this.layers.push(model);
            this.listenTo(model, 'toggle:enabled', this.layerToggled);
            this.listenTo(model, 'change', this.layerChanged);
            this.listenTo(model, 'toggle:colorScheme', this.layerChanged);
            var c = model.featureCollection;
            this.listenTo(c, {
                reset: this.featureReset
            });
            this.listenTo(c, 'add', this.featureAdd);
            this.listenTo(c, 'remove', this.featureRemove);
            this.listenTo(c, 'change', this.featureChange);
            this.listenTo(model, 'destroy', this.destroyLayer);

            this.featureReset(model.featureCollection);
        },

        layerToggled: function(model)
        {
        },

        layerChanged: function(model)
        {
        },

        drawLayer: function(model)
        {
        },

        destroyLayer: function(model)
        {
            this.layers.splice(this.layers.indexOf(model), 1);
            this.stopListening(model);
            this.stopListening(model.featureCollection);
        },

        /**
        * Map feature collection events
        */

        featureReset: function(collection, options) 
        {   
            var self = this;
            collection.each(function(model) {
                self.featureAdd(model, collection, options);
            });
            self.drawLayer(collection.mapLayer);
        },

        featureAdd: function(model, collection, options)  
        {
        },

        featureRemove: function(model, collection, options) 
        {
        },

        featureChange: function(model, options)
        {
        },

    });

    return MapViewBase;
});

{'fraction_non_alphanumeric': 0.10843373493975904, 'fraction_numerical': 0.0008309098462816784, 'mean_word_length': 1.572853580334877, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '7194960', 'n_tokens_mistral': 1902, 'n_tokens_neox': 1816, 'n_words': 315}