Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
restoring controller as instance rather than singleton
  • Loading branch information
caridy committed Oct 29, 2012
1 parent 9251274 commit c8c18ee
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
14 changes: 9 additions & 5 deletions lib/app/autoload/dispatch.common.js
Expand Up @@ -71,17 +71,21 @@ YUI.add('mojito-dispatcher', function(Y, NAME) {
Y.mojito.perf.mark('mojito', 'core_dispatch_start',
'dispatching an instance', command);

// Ensure there's a getController method we can call
// Ensure there's a createController method we can call
// that will always return a viable controller. By
// wrapping in a function we allow tests and other code
// to provide mocks etc.
instance.getController = instance.getController ||
// TODO: instance.createController should be part of the
// expandInstance routine rather than dispatch.
instance.createController = instance.createController ||
function() {
return Y.mojito.controllers[
// returning a controller instance instead of
// a singleton to avoid leaks.
return Y.mojito.util.heir(Y.mojito.controllers[
instance.controller
];
]);
};
controller = instance.getController();
controller = instance.createController();

perf = Y.mojito.perf.timeline('mojito', 'ac:ctor',
'create ControllerContext', command);
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/lib/app/autoload/test-dispatch.common.js
Expand Up @@ -33,7 +33,7 @@ YUI.add('mojito-dispatcher-tests', function(Y, NAME) {
id: 'xyz123',
instanceId: 'xyz123',
'controller-module': 'dispatch',
getController: function() {
createController: function() {
return { index: function() {} };
},
yui: {
Expand Down Expand Up @@ -83,7 +83,7 @@ YUI.add('mojito-dispatcher-tests', function(Y, NAME) {
id: 'xyz123',
instanceId: 'xyz123',
'controller-module': 'dispatch',
getController: function() {
createController: function() {
getterInvoked = true;
return { index: function() {} };
},
Expand Down Expand Up @@ -118,7 +118,7 @@ YUI.add('mojito-dispatcher-tests', function(Y, NAME) {
id: 'xyz123',
instanceId: 'xyz123',
'controller-module': 'dispatch',
getController: function() {
createController: function() {
return { index: function() {
actionInvoked = true;
} };
Expand Down

0 comments on commit c8c18ee

Please sign in to comment.