Skip to main content

I have this repetitive block of code and I'm looking for ways to make it reusable and as flat as possible.

Here it is:

    Controller.showKeyboardRegion = function() {
        logger.info('Controller.showKeyboardRegion => CreateAccountLayoutController');
 
        var view = new CreateAccountKeyboardView();
 
        Controller.layout.createAccountKeyboardRegion.show(view);
 
        view.startCreateAccountKeyboard();
    }

    Controller.showPhoneNumberRegion = function() {
        logger.info('Controller.showPhoneNumberRegion => CreateAccountLayoutController');
 
        var view = new CreateAccountPhoneNumberView();
 
        Controller.layout.createAccountPhoneNumberRegion.show(view);
 
        view.startCreateAccountPhoneNumber();
    }

    Controller.showNameRegion = function() {
        logger.info('Controller.showNameRegion => CreateAccountLayoutController');
 
        var view = new CreateAccountNameView();
 
        Controller.layout.createAccountNameRegion.show(view);
 
        view.startCreateAccountName();
    }

I have nine of those in my real code. Is there a way to make this simpler and better?

I have this repetitive block of code and I'm looking for ways to make it reusable and as flat as possible.

Here it is:

    Controller.showKeyboardRegion = function() {
        logger.info('Controller.showKeyboardRegion => CreateAccountLayoutController');
 
        var view = new CreateAccountKeyboardView();
 
        Controller.layout.createAccountKeyboardRegion.show(view);
 
        view.startCreateAccountKeyboard();
    }

    Controller.showPhoneNumberRegion = function() {
        logger.info('Controller.showPhoneNumberRegion => CreateAccountLayoutController');
 
        var view = new CreateAccountPhoneNumberView();
 
        Controller.layout.createAccountPhoneNumberRegion.show(view);
 
        view.startCreateAccountPhoneNumber();
    }

    Controller.showNameRegion = function() {
        logger.info('Controller.showNameRegion => CreateAccountLayoutController');
 
        var view = new CreateAccountNameView();
 
        Controller.layout.createAccountNameRegion.show(view);
 
        view.startCreateAccountName();
    }

I have nine of those in my real code. Is there a way to make this simpler and better?

I have this repetitive block of code and I'm looking for ways to make it reusable and as flat as possible.

Here it is:

Controller.showKeyboardRegion = function() {
    logger.info('Controller.showKeyboardRegion => CreateAccountLayoutController');
    var view = new CreateAccountKeyboardView();
    Controller.layout.createAccountKeyboardRegion.show(view);
    view.startCreateAccountKeyboard();
}

Controller.showPhoneNumberRegion = function() {
    logger.info('Controller.showPhoneNumberRegion => CreateAccountLayoutController');
    var view = new CreateAccountPhoneNumberView();
    Controller.layout.createAccountPhoneNumberRegion.show(view);
    view.startCreateAccountPhoneNumber();
}

Controller.showNameRegion = function() {
    logger.info('Controller.showNameRegion => CreateAccountLayoutController');
    var view = new CreateAccountNameView();
    Controller.layout.createAccountNameRegion.show(view);
    view.startCreateAccountName();
}

I have nine of those in my real code. Is there a way to make this simpler and better?

Source Link

Backbone Marionette code improvement

I have this repetitive block of code and I'm looking for ways to make it reusable and as flat as possible.

Here it is:

    Controller.showKeyboardRegion = function() {
        logger.info('Controller.showKeyboardRegion => CreateAccountLayoutController');

        var view = new CreateAccountKeyboardView();

        Controller.layout.createAccountKeyboardRegion.show(view);

        view.startCreateAccountKeyboard();
    }

    Controller.showPhoneNumberRegion = function() {
        logger.info('Controller.showPhoneNumberRegion => CreateAccountLayoutController');

        var view = new CreateAccountPhoneNumberView();

        Controller.layout.createAccountPhoneNumberRegion.show(view);

        view.startCreateAccountPhoneNumber();
    }

    Controller.showNameRegion = function() {
        logger.info('Controller.showNameRegion => CreateAccountLayoutController');

        var view = new CreateAccountNameView();

        Controller.layout.createAccountNameRegion.show(view);

        view.startCreateAccountName();
    }

I have nine of those in my real code. Is there a way to make this simpler and better?