diff --git a/app/app.js b/app/app.js index bb8694c..f94b131 100644 --- a/app/app.js +++ b/app/app.js @@ -4,8 +4,6 @@ views: {} }; - var servicesContainer = {}; - var controllersContainer = {}; var commandHandlers = {}; var runObservers = []; @@ -19,9 +17,16 @@ this.di.register(name, inst); }; + app.get = function(name) { + return this.di.resolve(name); + }; + app.service = app.component; - app.controller = app.component; + app.controller = function(name, inst) { + this.addControllerMixin(inst); + this.di.register(name, inst); + }; app.command = function(name, handler) { var cmd = commandHandlers[name]; @@ -52,6 +57,25 @@ window.app = app; + app.addControllerMixin = function (component) { + component.attachView = function(viewElement) { + + this.viewElement = viewElement; + + if(typeof component.onViewAttached == 'function') { + component.onViewAttached(viewElement); + } + }; + + component.detachView = function() { + + this.viewElement = null; + + if(typeof component.onViewDetached == 'function') { + component.onViewDetached(viewElement); + } + }; + } })(window.should, window.commandr, window.bindr, window.Container); \ No newline at end of file diff --git a/app/controllers.js b/app/controllers.js index 03ec621..6d843e0 100644 --- a/app/controllers.js +++ b/app/controllers.js @@ -2,9 +2,9 @@ app.controller('expressionInputCtrl', { $dispatcher:null, - attachView: function (viewElement) { + onViewAttached: function () { var d = this.$dispatcher; - viewElement.addEventListener('keyup', function (args) { + this.viewElement.addEventListener('keyup', function (args) { if (args.keyCode != 13) { return; } @@ -17,12 +17,6 @@ }); app.service('resultView', { - attachView: function(viewElement) { - this.viewElement = viewElement; - }, - detachView: function() { - this.viewElement = null; - }, clear: function (){ this.viewElement.innerHTML = ''; },