diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 51053e0..8424975 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -26,8 +26,8 @@ - - + + @@ -36,8 +36,18 @@ - - + + + + + + + + + + + + @@ -46,8 +56,8 @@ - - + + @@ -56,18 +66,8 @@ - - - - - - - - - - - - + + @@ -76,9 +76,12 @@ - - - + + + + + + @@ -116,8 +119,8 @@ - - + + @@ -169,11 +172,12 @@ @@ -422,7 +426,10 @@ - + + + + @@ -467,7 +474,10 @@ - + + + + @@ -513,7 +523,10 @@ - + + + + @@ -714,14 +727,6 @@ - - - - - - - - @@ -738,18 +743,53 @@ - + - - + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -762,42 +802,18 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - + + diff --git a/app/app.js b/app/app.js index f7b33db..bb8694c 100644 --- a/app/app.js +++ b/app/app.js @@ -11,31 +11,17 @@ app.di = new Container(); - function resolveOrInject(name, inst, container, entityName) { - var resolved; - - should.beString(name); - - if (inst != null) { - container[name] = inst; - console.log(name + " " + entityName + " registered"); - resolved = inst; - } - else { - resolved = container[name]; - should.check(resolved != null, name + " " + entityName + " wasn't found"); + app.component = function(name, inst) { + if(arguments.length == 1) { + return this.di.resolve(name); } - return resolved; - } - - app.service = function(name, inst) { - return resolveOrInject(name, inst, servicesContainer, "service"); + this.di.register(name, inst); }; - app.controller = function(name, inst) { - return resolveOrInject(name, inst, controllersContainer, "controller"); - }; + app.service = app.component; + + app.controller = app.component; app.command = function(name, handler) { var cmd = commandHandlers[name]; @@ -57,7 +43,7 @@ app.bootstrap = function(rootViewElement) { invokeRunObservers(); - bindr.bindControllers(rootViewElement, controllersContainer); + bindr.bindControllers(rootViewElement, app.di); }; function invokeRunObservers() { diff --git a/app/controllers.js b/app/controllers.js index 9a41bad..5ae3f9f 100644 --- a/app/controllers.js +++ b/app/controllers.js @@ -1,15 +1,16 @@ (function(app){ app.controller('expressionInputCtrl', { + $dispatcher:null, attachView: function (viewElement) { - var dispatcher = app.service('dispatcher'); + viewElement.addEventListener('keyup', function (args) { if (args.keyCode != 13) { return; } // Enter - dispatcher.dispatch(args.srcElement.value); + this.$dispatcher.dispatch(args.srcElement.value); args.srcElement.value = ''; }); } diff --git a/components/bindr.js b/components/bindr.js index 7a9f3bb..a5a24a5 100644 --- a/components/bindr.js +++ b/components/bindr.js @@ -72,25 +72,25 @@ }; - bindr.bindControllers = function (rootViewElement, controllers) { + bindr.bindControllers = function (rootViewElement, container) { var elements = rootViewElement.querySelectorAll('[data-controller]'), - i = 0, l = elements.length, name, ctrl, attached; + i = 0, l = elements.length, ctrlName, ctrl, attached; for(;i