Skip to content

Instantly share code, notes, and snippets.

@jquerygeek
Last active December 16, 2015 00:29
Show Gist options
  • Save jquerygeek/5348275 to your computer and use it in GitHub Desktop.
Save jquerygeek/5348275 to your computer and use it in GitHub Desktop.
initialize: function() {
this.route(':team/:user/:date', 'workdiary');
Backbone.history.start();
},
workdiary: function(team, user, date) {
this._load(); // _load() app method
}
@xjamundx
Copy link

xjamundx commented Apr 9, 2013

Here is our current _load function:

    _load: function(replace, reload) {
        if (this.replace) {
            replace = true;
            this.replace = false;
        }
        var team = this.config.get('team');
        if (!this._isTeamExists(team)) {
            if (!this.hasOtherSubteam(team)) {
                this._showIncorrectCompanyWarning();
            } else {
                this.config.set('team', this.teams.at(0).id);
                return;
            }
        }

        this.router.navigate(this._getUrl(), {
            replace: replace
        });
        this.users.setTeam(this.config.get('team'));
        this.workdiaryView.$el.html('').addClass('oLoading');
        this.workdiary.setReload(reload).fetch({
            success: this._fetchWorkdiarySuccess.bind(this),
            error: this._fetchWorkdiaryError.bind(this)
        });
        this.prefsPanel.render();
        this.teamsView.select(this.config.get('team'));
    },

I don't know what it's doing. Lots of random stuff.

here's how we can clean it up (more or less). Keep it very short.

_load: function() {
   this.checkTeam();
   this.router.navigate(this._getUrl());
   this.setTeam();
   // ...
},

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment