diff --git a/app/app.js b/app/app.js index c5198ea..2907863 100644 --- a/app/app.js +++ b/app/app.js @@ -1,7 +1,7 @@ -(function (should, Container, AppShell) { +(function (core) { - var di = new Container(); - var app = new AppShell(di); + var di = new core.Container(); + var app = new core.AppShell(di); app.debugMode = false; @@ -13,4 +13,4 @@ window.app = app; -})(window.should, window.Container, window.AppShell); \ No newline at end of file +})(window.core); \ No newline at end of file diff --git a/app/bitwise/calc.js b/app/bitwise/calc.js index f674bd1..1a1763f 100644 --- a/app/bitwise/calc.js +++ b/app/bitwise/calc.js @@ -1,4 +1,5 @@ -(function(app, should){ +app.compose(function() { + var should = app.get('should') app.set('calc', { numberOfBits: function (num) { @@ -18,4 +19,4 @@ } }); -})(window.app, window.should); +}); diff --git a/app/bitwise/expression.js b/app/bitwise/expression.js index 85c9b2e..bda01cf 100644 --- a/app/bitwise/expression.js +++ b/app/bitwise/expression.js @@ -1,10 +1,10 @@ -(function() { +app.compose(function(){ var twoOperandsRegex = /^(\d+)\s*(<<|>>|\||\&|\^)\s*(\d+)$/; var numbersList = /^((\d*)+\s?)+$/; app.set('expression', { canParse: function(string) { - return twoOperandsRegex.test(string) || numbersList.test(string); + return twoOperandsRegex.test(string) || numbersList.test(string); }, parse: function(string) { var trimmed = string.replace(/^\s+|\s+$/, ''); @@ -48,4 +48,4 @@ return new app.models.BitwiseNumbers(numbers); } -})(window.app); \ No newline at end of file +}); \ No newline at end of file diff --git a/app/bitwise/formatter.js b/app/bitwise/formatter.js index c2cee1e..134d82c 100644 --- a/app/bitwise/formatter.js +++ b/app/bitwise/formatter.js @@ -1,7 +1,7 @@ (function(should, app){ app.compose(function() { - + var should = app.get('should'); app.set("formatter", { toBinaryString: function(num, totalLength) { diff --git a/app/controllers.js b/app/controllers.js index 8e04bb5..7e39660 100644 --- a/app/controllers.js +++ b/app/controllers.js @@ -56,8 +56,7 @@ app.compose(function() { app.controller('resultViewCtrl', function() { var html = app.get('html'); - var resultViewController = { - $html: null, + return { clear: function (){ this.viewElement.innerHTML = ''; }, @@ -76,9 +75,6 @@ app.compose(function() { } } }; - - - return resultViewController; }); app.controller('configPanelCtrl', { diff --git a/app/services.js b/app/services.js index c4f6f69..93911fa 100644 --- a/app/services.js +++ b/app/services.js @@ -1,7 +1,8 @@ -(function(app, HtmlBuilder){ +(function(app, core){ - app.set('html', HtmlBuilder); - app.set('is', is); + app.set('html', core.HtmlBuilder); + app.set('is', core.is); + app.set('should', core.should) /* var template = { compile: function (template) { @@ -38,4 +39,4 @@ return str.replace(/(\r|\n)+/g, '').replace("'", "\\\'"); } */ -})(window.app, window.HtmlBuilder, window.is); \ No newline at end of file +})(window.app, window.core); \ No newline at end of file diff --git a/components/commandsFeature.js b/components/commandsFeature.js index 6193b27..6353f56 100644 --- a/components/commandsFeature.js +++ b/components/commandsFeature.js @@ -1,4 +1,7 @@ -(function(app){ +(function(app, core){ + + var should = core.should; + function Command(name) { this.name = name; this.executionHandlers = []; @@ -49,4 +52,5 @@ }; window.commandr = commandr; -})(window.app); \ No newline at end of file + +})(window.app, window.core); \ No newline at end of file diff --git a/components/controllersFeature.js b/components/controllersFeature.js index d453e19..1fc8196 100644 --- a/components/controllersFeature.js +++ b/components/controllersFeature.js @@ -1,22 +1,20 @@ -(function(app, should, Container) { +(function(app, core) { - var controllerDi = app.di; // TODO: Compbine + var should = core.should; app.controller = function(name, instOrFactory) { - should.beString(name, "name"); - if(instOrFactory == null) { - return controllerDi.resolve(name); + return this.get(name); } - var reg = new Container.Registration(instOrFactory); + var reg = new core.Container.Registration(instOrFactory); reg.onFirstTimeResolve = function (inst) { addControllerMixin(inst); }; - controllerDi.register(name, reg); + this.set(name, reg); }; app.run(function(){ @@ -78,4 +76,4 @@ } } -})(window.app, window.should, window.Container); +})(window.app, window.core); diff --git a/core/appShell.js b/core/appShell.js index e4958ac..d06859b 100644 --- a/core/appShell.js +++ b/core/appShell.js @@ -32,5 +32,5 @@ functions.forEach(function(o){ o(); }); } - window.AppShell = AppShell; + window.core.AppShell = AppShell; })(); \ No newline at end of file diff --git a/core/bindr.js b/core/bindr.js index 7bfc847..25ba1a2 100644 --- a/core/bindr.js +++ b/core/bindr.js @@ -50,5 +50,5 @@ }); } - window.bindr = bindr; + window.core.bindr = bindr; })(); \ No newline at end of file diff --git a/core/core.js b/core/core.js new file mode 100644 index 0000000..9dc2bff --- /dev/null +++ b/core/core.js @@ -0,0 +1 @@ +window.core = {}; diff --git a/core/di.js b/core/di.js index 5259752..ca9fbcc 100644 --- a/core/di.js +++ b/core/di.js @@ -1,6 +1,9 @@ // Problems: no check for the circular references -(function(is){ +(function(core){ + + var is = core.is; + function Container(store) { this.store = {}; this.resolutionStack = []; @@ -20,7 +23,7 @@ this.store[name] = reg; } - console.log(name + ' component registered'); + console.log('[' + name + '] component registered'); return reg; }; @@ -87,5 +90,5 @@ return false; } - window.Container = Container; -})(window.is); + core.Container = Container; +})(window.core); diff --git a/components/htmlBuilder.js b/core/htmlBuilder.js similarity index 93% rename from components/htmlBuilder.js rename to core/htmlBuilder.js index 488e1ab..7838099 100644 --- a/components/htmlBuilder.js +++ b/core/htmlBuilder.js @@ -1,6 +1,7 @@ -(function(){ +(function(core){ var HtmlBuilder = {}; + var should = core.should; HtmlBuilder.element = function(template, model) { var el = document.createElement('div'); @@ -55,6 +56,6 @@ .replace(/'/g, "'"); }; - window.HtmlBuilder = HtmlBuilder; + core.HtmlBuilder = HtmlBuilder; -})(); \ No newline at end of file +})(window.core); \ No newline at end of file diff --git a/core/is.js b/core/is.js index 38971e5..497c946 100644 --- a/core/is.js +++ b/core/is.js @@ -1,5 +1,5 @@ (function(){ - window.is = { + window.core.is = { plainObject: function(obj) { return typeof obj == "object" && obj instanceof Object; }, diff --git a/core/observable.js b/core/observable.js index 1256847..3f7a4cc 100644 --- a/core/observable.js +++ b/core/observable.js @@ -47,5 +47,5 @@ }); }; - window.observable = observable; + window.core.observable = observable; }); \ No newline at end of file diff --git a/core/should.js b/core/should.js index c1ba1df..0fe97dd 100644 --- a/core/should.js +++ b/core/should.js @@ -1,5 +1,5 @@ (function(){ - window.should = { + window.core.should = { beNumber: function (num, name) { this.check(typeof num == "number" && !isNaN(num), num + " is not a number"); this.check(isFinite(num), num + "is an infinite number") diff --git a/index.html b/index.html index 0890fb2..5b649c7 100644 --- a/index.html +++ b/index.html @@ -5,11 +5,12 @@