Introduced core.

This commit is contained in:
Borys Levytskyi
2015-04-04 16:33:33 +03:00
parent dd2175f04a
commit d96bcb0517
17 changed files with 48 additions and 42 deletions

View File

@@ -1,7 +1,7 @@
(function (should, Container, AppShell) { (function (core) {
var di = new Container(); var di = new core.Container();
var app = new AppShell(di); var app = new core.AppShell(di);
app.debugMode = false; app.debugMode = false;
@@ -13,4 +13,4 @@
window.app = app; window.app = app;
})(window.should, window.Container, window.AppShell); })(window.core);

View File

@@ -1,4 +1,5 @@
(function(app, should){ app.compose(function() {
var should = app.get('should')
app.set('calc', { app.set('calc', {
numberOfBits: function (num) { numberOfBits: function (num) {
@@ -18,4 +19,4 @@
} }
}); });
})(window.app, window.should); });

View File

@@ -1,4 +1,4 @@
(function() { app.compose(function(){
var twoOperandsRegex = /^(\d+)\s*(<<|>>|\||\&|\^)\s*(\d+)$/; var twoOperandsRegex = /^(\d+)\s*(<<|>>|\||\&|\^)\s*(\d+)$/;
var numbersList = /^((\d*)+\s?)+$/; var numbersList = /^((\d*)+\s?)+$/;
@@ -48,4 +48,4 @@
return new app.models.BitwiseNumbers(numbers); return new app.models.BitwiseNumbers(numbers);
} }
})(window.app); });

View File

@@ -1,7 +1,7 @@
(function(should, app){ (function(should, app){
app.compose(function() { app.compose(function() {
var should = app.get('should');
app.set("formatter", { app.set("formatter", {
toBinaryString: function(num, totalLength) { toBinaryString: function(num, totalLength) {

View File

@@ -56,8 +56,7 @@ app.compose(function() {
app.controller('resultViewCtrl', function() { app.controller('resultViewCtrl', function() {
var html = app.get('html'); var html = app.get('html');
var resultViewController = { return {
$html: null,
clear: function (){ clear: function (){
this.viewElement.innerHTML = ''; this.viewElement.innerHTML = '';
}, },
@@ -76,9 +75,6 @@ app.compose(function() {
} }
} }
}; };
return resultViewController;
}); });
app.controller('configPanelCtrl', { app.controller('configPanelCtrl', {

View File

@@ -1,7 +1,8 @@
(function(app, HtmlBuilder){ (function(app, core){
app.set('html', HtmlBuilder); app.set('html', core.HtmlBuilder);
app.set('is', is); app.set('is', core.is);
app.set('should', core.should)
/* /*
var template = { var template = {
compile: function (template) { compile: function (template) {
@@ -38,4 +39,4 @@
return str.replace(/(\r|\n)+/g, '').replace("'", "\\\'"); return str.replace(/(\r|\n)+/g, '').replace("'", "\\\'");
} }
*/ */
})(window.app, window.HtmlBuilder, window.is); })(window.app, window.core);

View File

@@ -1,4 +1,7 @@
(function(app){ (function(app, core){
var should = core.should;
function Command(name) { function Command(name) {
this.name = name; this.name = name;
this.executionHandlers = []; this.executionHandlers = [];
@@ -49,4 +52,5 @@
}; };
window.commandr = commandr; window.commandr = commandr;
})(window.app);
})(window.app, window.core);

View File

@@ -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) { app.controller = function(name, instOrFactory) {
should.beString(name, "name"); should.beString(name, "name");
if(instOrFactory == null) { 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) { reg.onFirstTimeResolve = function (inst) {
addControllerMixin(inst); addControllerMixin(inst);
}; };
controllerDi.register(name, reg); this.set(name, reg);
}; };
app.run(function(){ app.run(function(){
@@ -78,4 +76,4 @@
} }
} }
})(window.app, window.should, window.Container); })(window.app, window.core);

View File

@@ -32,5 +32,5 @@
functions.forEach(function(o){ o(); }); functions.forEach(function(o){ o(); });
} }
window.AppShell = AppShell; window.core.AppShell = AppShell;
})(); })();

View File

@@ -50,5 +50,5 @@
}); });
} }
window.bindr = bindr; window.core.bindr = bindr;
})(); })();

1
core/core.js Normal file
View File

@@ -0,0 +1 @@
window.core = {};

View File

@@ -1,6 +1,9 @@
// Problems: no check for the circular references // Problems: no check for the circular references
(function(is){ (function(core){
var is = core.is;
function Container(store) { function Container(store) {
this.store = {}; this.store = {};
this.resolutionStack = []; this.resolutionStack = [];
@@ -20,7 +23,7 @@
this.store[name] = reg; this.store[name] = reg;
} }
console.log(name + ' component registered'); console.log('[' + name + '] component registered');
return reg; return reg;
}; };
@@ -87,5 +90,5 @@
return false; return false;
} }
window.Container = Container; core.Container = Container;
})(window.is); })(window.core);

View File

@@ -1,6 +1,7 @@
(function(){ (function(core){
var HtmlBuilder = {}; var HtmlBuilder = {};
var should = core.should;
HtmlBuilder.element = function(template, model) { HtmlBuilder.element = function(template, model) {
var el = document.createElement('div'); var el = document.createElement('div');
@@ -55,6 +56,6 @@
.replace(/'/g, "&#039;"); .replace(/'/g, "&#039;");
}; };
window.HtmlBuilder = HtmlBuilder; core.HtmlBuilder = HtmlBuilder;
})(); })(window.core);

View File

@@ -1,5 +1,5 @@
(function(){ (function(){
window.is = { window.core.is = {
plainObject: function(obj) { plainObject: function(obj) {
return typeof obj == "object" && obj instanceof Object; return typeof obj == "object" && obj instanceof Object;
}, },

View File

@@ -47,5 +47,5 @@
}); });
}; };
window.observable = observable; window.core.observable = observable;
}); });

View File

@@ -1,5 +1,5 @@
(function(){ (function(){
window.should = { window.core.should = {
beNumber: function (num, name) { beNumber: function (num, name) {
this.check(typeof num == "number" && !isNaN(num), num + " is not a number"); this.check(typeof num == "number" && !isNaN(num), num + " is not a number");
this.check(isFinite(num), num + "is an infinite number") this.check(isFinite(num), num + "is an infinite number")

View File

@@ -5,11 +5,12 @@
<title></title> <title></title>
<script type="text/javascript" src="core/core.js"></script>
<script type="text/javascript" src="core/is.js"></script> <script type="text/javascript" src="core/is.js"></script>
<script type="text/javascript" src="core/should.js"></script> <script type="text/javascript" src="core/should.js"></script>
<script type="text/javascript" src="core/di.js"></script> <script type="text/javascript" src="core/di.js"></script>
<script type="text/javascript" src="core/appShell.js"></script> <script type="text/javascript" src="core/appShell.js"></script>
<script type="text/javascript" src="components/htmlBuilder.js"></script> <script type="text/javascript" src="core/htmlBuilder.js"></script>
<script type="text/javascript" src="app/app.js"></script> <script type="text/javascript" src="app/app.js"></script>