mirror of
https://github.com/BorysLevytskyi/BitwiseCmd.git
synced 2025-12-23 21:22: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: {}
|
||||
};
|
||||
|
||||
var servicesContainer = {};
|
||||
var controllersContainer = {};
|
||||
var commandHandlers = {};
|
||||
var runObservers = [];
|
||||
|
||||
@@ -19,9 +17,16 @@
|
||||
this.di.register(name, inst);
|
||||
};
|
||||
|
||||
app.get = function(name) {
|
||||
return this.di.resolve(name);
|
||||
};
|
||||
|
||||
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) {
|
||||
var cmd = commandHandlers[name];
|
||||
@@ -52,6 +57,25 @@
|
||||
|
||||
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);
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
app.controller('expressionInputCtrl', {
|
||||
$dispatcher:null,
|
||||
attachView: function (viewElement) {
|
||||
onViewAttached: function () {
|
||||
var d = this.$dispatcher;
|
||||
viewElement.addEventListener('keyup', function (args) {
|
||||
this.viewElement.addEventListener('keyup', function (args) {
|
||||
if (args.keyCode != 13) {
|
||||
return;
|
||||
}
|
||||
@@ -17,12 +17,6 @@
|
||||
});
|
||||
|
||||
app.service('resultView', {
|
||||
attachView: function(viewElement) {
|
||||
this.viewElement = viewElement;
|
||||
},
|
||||
detachView: function() {
|
||||
this.viewElement = null;
|
||||
},
|
||||
clear: function (){
|
||||
this.viewElement.innerHTML = '';
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user