patternjavascriptMinor
Controller for a vehicle servicing AJAX app
Viewed 0 times
ajaxservicingappcontrollerforvehicle
Problem
I am working on a codebase that operates in the following manner:
```
/*=========================================
= Table of Contents =
=========================================*/
/*
00 - Initializer
01 - Summary
02 - Consumer Lead
03 - General Services
04 - Products
05 - Quote
06 - Status
07 - Utility
*/
/----- End of Table of Contents ------/
(function($){
/*========================================
= 00 - Initializer =
========================================*/
/========== Constructor ==========/
/**
* Constructor for the controller. Creates the controller object and kicks of the
* creation of the app.
* @class controller
* @variation inspection-detail
* @instance
*/
var controller = function(){
var _this = this;
this.setRec = true;
dt_utils.setLoadal("show");
//Scoping all of the reused elements in order to save lookups.
this.defineEls();
//Creating instances of all the models and views.
this.createInstances();
//One function to rule them all.
this.setEventListeners();
this.inspectionuuid = dt_utils.getUrlParameterByName("inspection");
//As part of setEventListeners, we are listening to the ajaxStop event
//on the document. This allows us to call everything async and still ensure
//that all the data is present before we try to do logix.
//Makes things super fast.
this.inspectionDetails.fetch(function(e, inspection){
if (e != null){
dt_utils.handleError(e, true);
} else {
_this.consumerLead.fetch(fun
```
/*=========================================
= Table of Contents =
=========================================*/
/*
00 - Initializer
01 - Summary
02 - Consumer Lead
03 - General Services
04 - Products
05 - Quote
06 - Status
07 - Utility
*/
/----- End of Table of Contents ------/
(function($){
/*========================================
= 00 - Initializer =
========================================*/
/========== Constructor ==========/
/**
* Constructor for the controller. Creates the controller object and kicks of the
* creation of the app.
* @class controller
* @variation inspection-detail
* @instance
*/
var controller = function(){
var _this = this;
this.setRec = true;
dt_utils.setLoadal("show");
//Scoping all of the reused elements in order to save lookups.
this.defineEls();
//Creating instances of all the models and views.
this.createInstances();
//One function to rule them all.
this.setEventListeners();
this.inspectionuuid = dt_utils.getUrlParameterByName("inspection");
//As part of setEventListeners, we are listening to the ajaxStop event
//on the document. This allows us to call everything async and still ensure
//that all the data is present before we try to do logix.
//Makes things super fast.
this.inspectionDetails.fetch(function(e, inspection){
if (e != null){
dt_utils.handleError(e, true);
} else {
_this.consumerLead.fetch(fun
Solution
Due to the volume of code, I would be inclined not to touch it. Recoding and revalidating would be a lengthy exercise.
I wonder if the way ahead might be to enhance the (already good) comments, to provide better guidance to the existing architecture.
If I was to make any changes to the code at all, the first thing would be to give the overloaded Controller (instance) namespace some internal structure. To make it clearer what's what in the rest of the code-base, you could put :
Possibly also the 27 jQuery collections, though the
Then do a lengthy, careful trawl to pick up on the new structures.
I wonder if the way ahead might be to enhance the (already good) comments, to provide better guidance to the existing architecture.
controller.prototype.mainCallback(and the way it is called) is effectively the app's "digest cycle". For anyone coming from a declaritive background, particularly Angular, that term will be familiar and something like "This is effectively the app's digest cycle" could sensibly be included in mainCallback's description block.
- Your own paragraph in the question, "As you can see, the models are ..." is a good introduction to the overall architecture and could be also worked into the mainCallback's description block.
If I was to make any changes to the code at all, the first thing would be to give the overloaded Controller (instance) namespace some internal structure. To make it clearer what's what in the rest of the code-base, you could put :
- 17 x
new comp.model...- into athis.modelsobject,
- 7 x
new comp.ui...- into athis.uisobject,
- 7 x
new insp.view...- into athis.viewsobject.
Possibly also the 27 jQuery collections, though the
$ prefix already identifies them pretty well.Then do a lengthy, careful trawl to pick up on the new structures.
Context
StackExchange Code Review Q#119528, answer score: 2
Revisions (0)
No revisions yet.