<commit_before>﻿// @reference app.models.appstate.js
// @reference app.models.players.js
// @reference app.models.turns.js
// @reference app.views.header.js
// @reference app.views.turns.js
// @reference app.views.players.js
(function ($, backbone, app, undefined) {
    "use strict";

    //var turns = new Turns();
    //turns.fetch();

    // define a custom close method
    // if special clean-up is necessary,
    // create a beforeClose function
    // see http://lostechies.com/derickbailey/2011/09/15/zombies-run-managing-page-transitions-in-backbone-apps/
    backbone.View.prototype.close = function () {
        if (this.beforeClose)
            this.beforeClose();
        this.remove();
        this.unbind();
    };

    // application router, create as instantiated singleton
    app.router = new (backbone.Router.extend({
        routes: {
            'turns': 'turns',
            'completed': 'completed',
            'players': 'players',
            '*other': 'turns'
        },
        initialize: function (options) {
            _.bindAll(this);
            // save references to models
            this.appState = options.app_state;
            this.turns = options.turns;
            this.players = options.players;
            // notify appState when changing routes
            var self = this;
            _(this.routes).each(function (route) {
                self.on('route:' + route, function () {
                    // TODO: Need error handling
                    self.appState[route + 'Menu']();
                });
            });
            // place a header first in the body element
            this.header = new app.Views.Header({ model: options.app_state, router: this });
            $("body").prepend(this.header.render().el);
        },
        // handles views
        showView: function (selector, view) {
            if (this.currentView)
                this.currentView.close();
            $(selector).html(view.render().el);
            this.currentView = view;
            return view;
        },
        // routes
        // show coming turns
        turns: function () {
            var turns_view = new app.Views.Turns({ collection: this.turns });
            this.showView("#main", turns_view);
        },
        // show completed turns
        completed: function () {
        },<commit_msg>Improved error handling<commit_after>﻿// @reference app.models.appstate.js
// @reference app.models.players.js
// @reference app.models.turns.js
// @reference app.views.header.js
// @reference app.views.turns.js
// @reference app.views.players.js
(function ($, backbone, app, undefined) {
    "use strict";

    //var turns = new Turns();
    //turns.fetch();

    // define a custom close method
    // if special clean-up is necessary,
    // create a beforeClose function
    // see http://lostechies.com/derickbailey/2011/09/15/zombies-run-managing-page-transitions-in-backbone-apps/
    backbone.View.prototype.close = function () {
        if (this.beforeClose)
            this.beforeClose();
        this.remove();
        this.unbind();
    };

    // application router, create as instantiated singleton
    app.router = new (backbone.Router.extend({
        routes: {
            'turns': 'turns',
            'completed': 'completed',
            'players': 'players',
            '*other': 'turns'
        },
        initialize: function (options) {
            _.bindAll(this);
            // save references to models
            this.appState = options.app_state;
            this.turns = options.turns;
            this.players = options.players;
            // notify appState when changing routes
            var self = this;
            _(this.routes).each(function (route) {
                self.on('route:' + route, function () {
                    var f = self.appState[route + 'Menu'];
                    if (f === null || typeof f !== 'function')
                        throw Error('Missing handler for ' + route + 'Menu in appState');
                    f.apply(self.appState);
                });
            });
            // place a header first in the body element
            this.header = new app.Views.Header({ model: options.app_state, router: this });
            $("body").prepend(this.header.render().el);
        },
        // handles views
        showView: function (selector, view) {
            if (this.currentView)
                this.currentView.close();
            $(selector).html(view.render().el);
            this.currentView = view;
            return view;
        },
        // routes
        // show coming turns
        turns: function () {
            var turns_view = new app.Views.Turns({ collection: this.turns });
            this.showView("#main", turns_view);
        },
        // show completed turns
        completed: function () {
        },
{'fraction_non_alphanumeric': 0.13316892725030827, 'fraction_numerical': 0.0032881216605014385, 'mean_word_length': 1.7099109131403119, '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': '5879000', 'n_tokens_mistral': 1338, 'n_tokens_neox': 1301, 'n_words': 309}