diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 0e9af16..7783b8f 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -37,14 +37,14 @@ - + - + @@ -53,10 +53,10 @@ - - + + - + @@ -66,8 +66,18 @@ - - + + + + + + + + + + + + @@ -76,13 +86,23 @@ - + + + + + + + + + + + @@ -93,18 +113,8 @@ - - - - - - - - - - - - + + @@ -113,16 +123,6 @@ - - - - - - - - - - @@ -152,12 +152,14 @@ @@ -167,6 +169,25 @@ - + - - + + - + - - + + - - - - - - - - - + @@ -763,26 +792,18 @@ - - - - - - - - - - + + - + - - + + diff --git a/index.html b/index.html index 11b5887..13fff09 100644 --- a/index.html +++ b/index.html @@ -6,12 +6,13 @@ - + + - - - + + + @@ -41,7 +42,7 @@ expressionInputCtrl.bind(document.getElementById('in'), model); - app.command('calculateExpression').subscribe(function() { + app.command('calculateExpression', function() { var expr = expression.parse(model.expression); if(expr == null) { diff --git a/js/app.js b/js/app.js index 2ab6797..79ac2ec 100644 --- a/js/app.js +++ b/js/app.js @@ -1,11 +1,11 @@ -(function (should, bindr) { +(function (should, commandr) { var app = {}; app.views = {}; var servicesContainer = {}; var controllersContainer = {}; - var events = {}; + var commands = {}; function resolveOrInject(name, inst, container, entityName) { var resolved; @@ -33,30 +33,22 @@ return resolveOrInject(name, inst, controllersContainer, "controller"); }; - app.command = function(name) { - var evt = events[name]; - if(evt == null) { - evt = events[name] = new Command(name); + app.command = function(name, handler) { + var cmd = commands[name]; + + if(cmd == null) { + cmd = commands[name] = new commandr.Command(name); } - return evt; + + if(typeof handler == "function") { + cmd.subscribe(handler); + } + + return cmd; }; window.app = app; - function Command(name) { - this.name = name; - this.handlers = []; - } - Command.prototype.fire = function (arg) { - for(var i=0; i<1; i++) { - this.handlers[i](arg); - } - }; - Command.prototype.subscribe = function (handler) { - this.handlers.push(handler); - // TODO: unsubcribe - } - -})(window.should); \ No newline at end of file +})(window.should, window.commandr); \ No newline at end of file diff --git a/js/components/calc.js b/js/calc.js similarity index 100% rename from js/components/calc.js rename to js/calc.js diff --git a/js/components/commandr.js b/js/components/commandr.js new file mode 100644 index 0000000..b3d2665 --- /dev/null +++ b/js/components/commandr.js @@ -0,0 +1,25 @@ +(function(){ + var commandr = { + + }; + + function Command(name) { + this.name = name; + this.handlers = []; + } + + Command.prototype.fire = function (arg) { + for(var i=0; i<1; i++) { + this.handlers[i](arg); + } + }; + + Command.prototype.subscribe = function (handler) { + this.handlers.push(handler); + // TODO: unsubcribe + }; + + commandr.Command = Command; + + window.commandr = commandr; +})(); \ No newline at end of file diff --git a/js/components/core.js b/js/components/should.js similarity index 100% rename from js/components/core.js rename to js/components/should.js diff --git a/js/components/expression.js b/js/expression.js similarity index 100% rename from js/components/expression.js rename to js/expression.js diff --git a/js/components/formatter.js b/js/formatter.js similarity index 100% rename from js/components/formatter.js rename to js/formatter.js