mirror of
https://github.com/kbparagua/paloma
synced 2023-03-27 23:21:17 -04:00
adjust Paloma.Engine to use new ControllerBuilder
This commit is contained in:
parent
2bf55339ec
commit
13f07269a1
4 changed files with 67 additions and 22 deletions
34
vendor/assets/javascripts/paloma/controller_builder.js
vendored
Normal file
34
vendor/assets/javascripts/paloma/controller_builder.js
vendored
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
Paloma.ControllerBuilder = function(classFactory){
|
||||||
|
this.classFactory = classFactory;
|
||||||
|
this.options = {};
|
||||||
|
};
|
||||||
|
|
||||||
|
Paloma.ControllerBuilder.prototype = {
|
||||||
|
|
||||||
|
build: function(options){
|
||||||
|
this.options = options;
|
||||||
|
|
||||||
|
var ControllerClass = this._controllerClass(),
|
||||||
|
if ( !ControllerClass ) return null;
|
||||||
|
|
||||||
|
return new ControllerClass( this._buildParams() );
|
||||||
|
},
|
||||||
|
|
||||||
|
_controllerClass: function(){
|
||||||
|
return this.classFactory.get( this.options.controller );
|
||||||
|
},
|
||||||
|
|
||||||
|
_buildParams: function(){
|
||||||
|
var params = {
|
||||||
|
_controller: this.options.controller,
|
||||||
|
_action: this.options.action
|
||||||
|
};
|
||||||
|
|
||||||
|
for (var k in this.options.params)
|
||||||
|
if (this.options.hasOwnProperty(k))
|
||||||
|
params[k] = this.options.params[k];
|
||||||
|
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
31
vendor/assets/javascripts/paloma/engine.js
vendored
31
vendor/assets/javascripts/paloma/engine.js
vendored
|
@ -1,5 +1,5 @@
|
||||||
Paloma.Engine = function(config){
|
Paloma.Engine = function(controllerBuilder){
|
||||||
this.builder = config.builder;
|
this.controllerBuilder = controllerBuilder;
|
||||||
this._clearRequest();
|
this._clearRequest();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -29,27 +29,31 @@ Paloma.Engine.prototype = {
|
||||||
this._logRequest();
|
this._logRequest();
|
||||||
this._lastRequest = this._request;
|
this._lastRequest = this._request;
|
||||||
|
|
||||||
var controllerClass = this.builder.get( this._request.controller );
|
this._executeControllerAction();
|
||||||
|
|
||||||
if (controllerClass){
|
|
||||||
var controller = new controllerClass( this._request.params );
|
|
||||||
this._executeActionOf(controller);
|
|
||||||
}
|
|
||||||
|
|
||||||
this._clearRequest();
|
this._clearRequest();
|
||||||
},
|
},
|
||||||
|
|
||||||
_executeActionOf: function(controller){
|
_executeControllerAction: function(){
|
||||||
var action = controller[ this._request.action ];
|
var controller = this._buildController();
|
||||||
|
if (!controller) return;
|
||||||
|
|
||||||
|
var action = controller[ this._request.action ];
|
||||||
|
if (!action) return;
|
||||||
|
|
||||||
if (action){
|
|
||||||
var callbackPerformer = new Paloma.BeforeCallbackPerformer(controller);
|
var callbackPerformer = new Paloma.BeforeCallbackPerformer(controller);
|
||||||
callbackPerformer.perform( this._request.action );
|
callbackPerformer.perform( this._request.action );
|
||||||
|
|
||||||
action.call(controller);
|
action.call(controller);
|
||||||
|
|
||||||
this._lastRequest.executed = true;
|
this._lastRequest.executed = true;
|
||||||
}
|
},
|
||||||
|
|
||||||
|
_buildController: function(){
|
||||||
|
return this.controllerBuilder.build({
|
||||||
|
controller: this._request.controller,
|
||||||
|
action: this._request.action,
|
||||||
|
params: this._request.params
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
_shouldStop: function(){
|
_shouldStop: function(){
|
||||||
|
@ -71,4 +75,5 @@ Paloma.Engine.prototype = {
|
||||||
_clearRequest: function(){
|
_clearRequest: function(){
|
||||||
this._request = null;
|
this._request = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
1
vendor/assets/javascripts/paloma/index.js
vendored
1
vendor/assets/javascripts/paloma/index.js
vendored
|
@ -2,5 +2,6 @@
|
||||||
//= require ./base_controller.js
|
//= require ./base_controller.js
|
||||||
//= require ./controller_class_factory.js
|
//= require ./controller_class_factory.js
|
||||||
//= require ./before_callback_performer.js
|
//= require ./before_callback_performer.js
|
||||||
|
//= require ./controller_builder.js
|
||||||
//= require ./engine.js
|
//= require ./engine.js
|
||||||
//= require ./paloma.js
|
//= require ./paloma.js
|
||||||
|
|
17
vendor/assets/javascripts/paloma/paloma.js
vendored
17
vendor/assets/javascripts/paloma/paloma.js
vendored
|
@ -1,10 +1,15 @@
|
||||||
(function(Paloma){
|
(function(Paloma){
|
||||||
|
|
||||||
Paloma._controllerClassFactory = new Paloma.ControllerClassFactory();
|
var classFactory = new Paloma.ControllerClassFactory(),
|
||||||
Paloma.engine = new Paloma.Engine({builder: Paloma._controllerBuilder});
|
controllerBuilder = new Paloma.ControllerBuilder(classFactory),
|
||||||
|
engine = new Paloma.Engine(controllerBuilder)
|
||||||
|
|
||||||
|
Paloma._controllerClassFactory = classFactory;
|
||||||
|
Paloma._controllerBuilder = controllerBuilder
|
||||||
|
Paloma.engine = engine;
|
||||||
|
|
||||||
Paloma.controller = function(name, prototype){
|
Paloma.controller = function(name, prototype){
|
||||||
return Paloma._controllerClassFactory.make(name, prototype);
|
return classFactory.make(name, prototype);
|
||||||
};
|
};
|
||||||
|
|
||||||
Paloma._executeHook = function(){
|
Paloma._executeHook = function(){
|
||||||
|
@ -13,12 +18,12 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
Paloma.start = function(){
|
Paloma.start = function(){
|
||||||
if ( !this.engine.hasRequest() ) this._executeHook();
|
if ( !engine.hasRequest() ) this._executeHook();
|
||||||
if ( this.engine.hasRequest() ) this.engine.start();
|
if ( engine.hasRequest() ) engine.start();
|
||||||
};
|
};
|
||||||
|
|
||||||
Paloma.isExecuted = function(){
|
Paloma.isExecuted = function(){
|
||||||
return this.engine.lastRequest().executed;
|
return engine.lastRequest().executed;
|
||||||
};
|
};
|
||||||
|
|
||||||
})(window.Paloma);
|
})(window.Paloma);
|
||||||
|
|
Loading…
Reference in a new issue