<commit_before>"use strict";
// Start the main app logic.
define([
    "underscore",
    "couchutils"
], function(_, couchUtils) {
    // app is already instantiated (as singleton), so simply add events to it.
    var eventInitializer = {
        setupAppEvents: function (app) {
            app.on({
                "app:requestLogin": function(data) {
                    console.info("[app]", "requestLogin", data);
                    couchUtils.login(data.username, data.password)
                        .done(function() {
                            console.log("Logged in!");
                            // Proceed to main page.
                            app.trigger("app:navigate", {url: "main"});
                        })
                        .fail(function() {
                            console.warn("Login failed!");
                            // Stay on current page.
                            // TODO: warn user about login failure.
                        });
                },
                "app:navigate": function(data) {
                    // This call is a little different than the native Backbone navigate,
                    // to keep it similar to all other calls: {url: String, options: Object}.
                    console.info("[app]", "navigate", data);
                    app.router.navigate(data.url, _.extend({}, data.options));
                }

            });
        },

        /**
         * Direct way to connect views to app event handler.
         * Each view must be connected to the event router **here**.
         **/
        hookupAppEvents: function (app) {
            app.views.loginPageView.on("all", _.bind(function(eventName, data) {
                app.trigger(eventName, data);
            }, this));
        }
    };

    return eventInitializer;
});<commit_msg>Improve app event hookup & app:navigate event handling<commit_after>"use strict";
// Start the main app logic.
define([
    "underscore",
    "couchutils"
], function(_, couchUtils) {
    // app is already instantiated (as singleton), so simply add events to it.
    var eventInitializer = {
        setupAppEvents: function (app) {
            app.on({
                "app:requestLogin": function(data) {
                    console.info("[app]", "requestLogin", data);
                    couchUtils.login(data.username, data.password)
                        .done(function() {
                            console.log("Logged in!");
                            // Proceed to main page.
                            app.trigger("app:navigate", {url: "main"});
                        })
                        .fail(function() {
                            console.warn("Login failed!");
                            // Stay on current page.
                            // TODO: warn user about login failure.
                        });
                },
                "app:navigate": function(data) {
                    // This call is a little different than the native Backbone navigate,
                    // to keep it similar to all other calls: {url: String, options: Object}.
                    console.info("[app]", "navigate", data);
                    // By default, trigger the route method; to disable, set ``trigger==false``.
                    // This is opposite of Backbone's default.
                    app.router.navigate(data.url, _.extend({trigger: true}, data.options));
                }

            });
        },

        /**
         * Direct way to connect views to app event handler.
         * Each view must be connected to the event router **here**.
         **/
        hookupAppEvents: function (app) {
            // Hook up specific views' events.
            _.each([app.views.loginPageView, app.views.mainPageView],
                function(view) {
                    view.on("all", _.bind(function(eventName, data) {
                        app.trigger(eventName, data);
                    }, this));
                }, this);
            // app.views.loginPageView.on("all", _.bind(function(eventName, data) {
            //     app.trigger(eventName, data);
            // }, this));
        }
    };

    return eventInitializer;
});
{'fraction_non_alphanumeric': 0.11766098484848485, 'fraction_numerical': 0.0, 'mean_word_length': 1.2974442631865144, 'pattern_counts': {'":': 4, '<': 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': '4035884', 'n_tokens_mistral': 1027, 'n_tokens_neox': 980, 'n_words': 280}