0
\$\begingroup\$

I use the the View below to get things started. I'm not interested in Marionette.

This code is what is constructed when the application first loads. It in turn loads the composite view which is common to all loads. It also constructs other objects needed for the application.

I'm looking for feedback on code structure and not naming conventions.

/***********************************************************************************************************************
** BVApp
*/


    var BVApp = Backbone.View.extend({
        Name: 'BVApp',
        el: window,
        initialize: function () {
            var token = Storage.getToken(),
                pub_req = $A.Reg.get('pub_req');

            // View like objects - inject DOM elements needed
            var BodyInstance = new Body(document.body);
            var ErrorHandlerInstance = new ErrorHandler(document.body);
            var TitleAjaxInstance = new TitleAjax($A.el("#timer"));

            this.setFrame();
            this.loadCommonViews();
            if (pub_req) {
                Page.flip('splash');
            } else if (!token) {
                Page.flip('splash');
            } else {
                this.loadViews(token);
            }
        },
        setFrame: function () {
            var test = $A.el('#super-1');
            if(test){
                test.style.display='none';
            }
            $A.el('#mega_wrap').style.display='inherit';
        },
        loadCommonViews: function () {
            $A.Mod.add(new BVFave({el: $A.el('#fm'), collection: new BCFave([], {data: {h_token: "1FOO", model: "FavoriteReader"}})}));
            $A.Mod.add(new BVFeed({el: $A.el('#at_view'), collection: new BCFeed([], {data: {h_token: "1FOO", model: "FeedReader"}})}));
        },
        loadViews: function (token) {
            var composite_view = $A.Mod.add(new BVComposite());
            composite_view.render(token);
            Page.flip(Storage.get('page'));
        }
    });
\$\endgroup\$
1
  • 1
    \$\begingroup\$ Looking for feedback on code structure and not naming conventions. that's entirely up to reviewers, which are always free to comment on any & all aspects of your code. If there's nothing to say about your naming conventions, then nothing will be said. If it's a low-hanging fruit, fix it before posting, or expect answers that mention it. \$\endgroup\$ Commented May 25, 2016 at 0:20

1 Answer 1

1
\$\begingroup\$

You should shorten this up

if (pub_req) {
    Page.flip('splash');
} else if (!token) {
    Page.flip('splash');
} else {
    this.loadViews(token);
}

by merging the first two if statements, like this

if (pub_req || !token) {
    Page.flip('splash');
} else {
    this.loadViews(token);
}

This evaluates in exactly the same order as your code did, but it is shorter.


// View like objects - inject DOM elements needed
var BodyInstance = new Body(document.body);
var ErrorHandlerInstance = new ErrorHandler(document.body);
var TitleAjaxInstance = new TitleAjax($A.el("#timer"));

You have declared these variables but then you don't use any of them, anywhere in the code that you have posted, I can only assume that you don't need these and that you should remove the dead code laying around in your code.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.