Skip to content

Commit

Permalink
Added Tracing DeftJS Controller Inheritance for debugging. Modified t…
Browse files Browse the repository at this point in the history
…o only allow the first defined controller, rather than the last superclass.
  • Loading branch information
CasualNetworks committed Jul 3, 2012
1 parent 09d206d commit 971dc02
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions build/deft-debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ Ext.define('Deft.mvc.ViewController', {
Ext.define('Deft.mixin.Controllable', {});

Ext.Class.registerPreprocessor('controller', function (Class, data, hooks, callback) {
var controllerClass, originalConstructor, originalDestroy, parameters, self;
var controllerClass, originalConstructor, originalDestroy, parameters, self, controllerState, superclassController;
if (arguments.length === 3) {
parameters = Ext.toArray(arguments);
hooks = parameters[1];
Expand All @@ -646,6 +646,13 @@ Ext.Class.registerPreprocessor('controller', function (Class, data, hooks, callb
controllerClass = data.controller;
delete data.controller;
if (controllerClass != null) {

This comment has been minimized.

Copy link
@cnstaging

cnstaging Jul 3, 2012

Owner

Here we setup some Tracing DeftJS Controller Inheritance for debugging, even though there is no flag to turn it off.

Also messing with prototypes like this is messy, again only used for debugging in our testing.

if (!this.__proto__.controllerState) {
this.__proto__.controllerState = {deftJS : {currentController : undefined, controllerChain : {attempted : [], processed : []}}};
}
controllerState = this.__proto__.controllerState;
controllerState.deftJS.controllerChain.attempted.push({id : Ext.id(undefined, 'attempted-controller'), class : controllerClass});

if (!data.hasOwnProperty('constructor')) {
data.constructor = function () {
return this.callParent(arguments);
Expand All @@ -657,12 +664,22 @@ Ext.Class.registerPreprocessor('controller', function (Class, data, hooks, callb
if (config == null) {
config = {};
}
try {
controller = Ext.create(controllerClass, config.controllerConfig || this.controllerConfig || {});
} catch (error) {
Deft.Logger.warn("Error initializing Controllable instance: an error occurred while creating an instance of the specified controller: '" + controllerClass + "'.");
throw error;
// TODO - This is too brute force, only accepts the first controller to be defined. That controller then must manage it's own 'Deft.mvc.ViewController' inheritance.
if (controllerState.deftJS.controllerChain.processed.length > 0) {

This comment has been minimized.

Copy link
@cnstaging

cnstaging Jul 3, 2012

Owner

A quick check to see if we have already registered a controller or not. If we have, then just use that controller and move on...

Their is problems with this approach for various reasons, mostly the fact that we don't exit out and run this function on each class for every level of inheritance. That first defined controller then must manage it's own 'Deft.mvc.ViewController' inheritance. Which in our use, it does.

//superclassController = Class && Class.controller ? Class.superclass.controller : false;
console.warn("We should stop and do something here!");
controller = controllerState.deftJS.currentController;
} else {
controllerState.deftJS.controllerChain.processed.push(controllerClass);
try {
controller = Ext.create(controllerClass, config.controllerConfig || this.controllerConfig || {});
controllerState.deftJS.currentController = controller;
} catch (error) {
Deft.Logger.warn("Error initializing Controllable instance: an error occurred while creating an instance of the specified controller: '" + controllerClass + "'.");
throw error;
}
}

this.getController = function () {
return controller;
};
Expand Down

0 comments on commit 971dc02

Please sign in to comment.