mirror of
https://github.com/BorysLevytskyi/BitwiseCmd.git
synced 2025-12-23 05:02:48 +01:00
Implemented controller as a mixin
This commit is contained in:
30
app/app.js
30
app/app.js
@@ -4,8 +4,6 @@
|
|||||||
views: {}
|
views: {}
|
||||||
};
|
};
|
||||||
|
|
||||||
var servicesContainer = {};
|
|
||||||
var controllersContainer = {};
|
|
||||||
var commandHandlers = {};
|
var commandHandlers = {};
|
||||||
var runObservers = [];
|
var runObservers = [];
|
||||||
|
|
||||||
@@ -19,9 +17,16 @@
|
|||||||
this.di.register(name, inst);
|
this.di.register(name, inst);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
app.get = function(name) {
|
||||||
|
return this.di.resolve(name);
|
||||||
|
};
|
||||||
|
|
||||||
app.service = app.component;
|
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) {
|
app.command = function(name, handler) {
|
||||||
var cmd = commandHandlers[name];
|
var cmd = commandHandlers[name];
|
||||||
@@ -52,6 +57,25 @@
|
|||||||
|
|
||||||
window.app = app;
|
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);
|
})(window.should, window.commandr, window.bindr, window.Container);
|
||||||
@@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
app.controller('expressionInputCtrl', {
|
app.controller('expressionInputCtrl', {
|
||||||
$dispatcher:null,
|
$dispatcher:null,
|
||||||
attachView: function (viewElement) {
|
onViewAttached: function () {
|
||||||
var d = this.$dispatcher;
|
var d = this.$dispatcher;
|
||||||
viewElement.addEventListener('keyup', function (args) {
|
this.viewElement.addEventListener('keyup', function (args) {
|
||||||
if (args.keyCode != 13) {
|
if (args.keyCode != 13) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -17,12 +17,6 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
app.service('resultView', {
|
app.service('resultView', {
|
||||||
attachView: function(viewElement) {
|
|
||||||
this.viewElement = viewElement;
|
|
||||||
},
|
|
||||||
detachView: function() {
|
|
||||||
this.viewElement = null;
|
|
||||||
},
|
|
||||||
clear: function (){
|
clear: function (){
|
||||||
this.viewElement.innerHTML = '';
|
this.viewElement.innerHTML = '';
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user