1
0
Fork 0
mirror of https://github.com/kbparagua/paloma synced 2023-03-27 23:21:17 -04:00

Add "all" action"

This commit is contained in:
kbparagua 2016-03-16 00:02:07 +08:00
parent a3a2d6bc9e
commit fbe4d7f2ff
3 changed files with 15 additions and 6 deletions

View file

@ -38,6 +38,7 @@ Paloma.controller('Application', {
// ],
before: [
'all -> performThis',
'show -> doSomething'
],
@ -47,6 +48,10 @@ Paloma.controller('Application', {
doSomething: function(){
console.log('Do something');
},
performThis: function(){
console.log('Perform This!');
}
});

View file

@ -6,16 +6,16 @@ Paloma.Agent.prototype = {
perform: function(action){
var callbacks = this._getCallbacksFor(action);
this._executeCallbacks.call(callbacks);
this._executeCallbacks(callbacks);
},
_getCallbacksFor: function(action){
var callbacks = [];
for (var i = 0, n = this.controller.before.length; i < n; i++){
var entry = parseEntry( this.before[i] );
var entry = this._parseEntry( this.controller.before[i] );
if ( entry.methods.indexOf(methodName) != -1 )
if ( this._methodIsIncluded(action, entry.methods) )
callbacks = callbacks.concat(entry.callbacks);
}
@ -32,14 +32,18 @@ Paloma.Agent.prototype = {
return data;
},
_methodIsIncluded: function(name, methods){
return methods.indexOf(name) != -1 || methods.indexOf('all') != -1;
},
_executeCallbacks: function(callbacks){
for (var i = 0, n = callbacks.length; i < n; i++){
var name = callbacks[i],
callback = this.controller[name];
callback.call(this.controller);
if (callback) callback.call(this.controller);
}
};
}
};

View file

@ -43,7 +43,7 @@ Paloma.Engine.prototype = {
var action = controller[ this._request.action ];
if (action){
var agent = Paloma.Agent(controller);
var agent = new Paloma.Agent(controller);
agent.perform( this._request.action );
this._lastRequest.executed = true;