Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

bugfix for @PostConstruct, @PreDestry and for non-functional members

  • Loading branch information...
commit 0fc727781eb2ce7bc34b35d3e2a0ef0fabd0b560 1 parent 55ebaa5
@warmuuh authored
View
36 yaap/wire/express/plugins/VerbProcessors.js
@@ -25,19 +25,33 @@ function(when, _) {
function registerExpressCallback(path, fnExpress, obj, fnDescription, context){
path = path || '/' + fnDescription.name; //in case of no-argument annotation, use fnName as endpoint
+
+ //prepend basename
+ if (obj["@Path"] != null) //null or undefind
+ path = obj["@Path"] + path;
+
+ console.log("Registering route: " + path);
+
fnExpress(path, function(req, res, next){
-
- var args = processParameters(req, fnDescription);
+ var responseSent = false;
+ var sendResponse = function(result){
+ responseSent = true;
+ processResponse(result, res, fnDescription, context);
+ };
+
+ var args = processParameters(req, fnDescription, sendResponse);
//execution
var result = obj[fnDescription.name].apply(obj, args); //dynamic call because there could be other annotations
- processResponse(result, res, fnDescription, context);
+ //if it is undefined, then there *should* be a callback ;)
+ if (result !== undefined && !responseSent)
+ sendResponse(result);
});
}
- function processParameters(req, fnDescription){
+ function processParameters(req, fnDescription, responseCallback){
var args = [];
var processEveryParameter = (getAnnotation(fnDescription, "@Param") !== undefined);
@@ -47,9 +61,10 @@ function(when, _) {
//handle @Param
var annoParam = getAnnotation(param, "@Param");
var annoBody = getAnnotation(param, "@Body");
+ var cb = getAnnotation(param, "@Callback");
- if ((processEveryParameter && annoBody === undefined) //NO other annotations allowed because it would be overwritten
+ if ((processEveryParameter && annoBody === undefined && cb === undefined) //NO other annotations allowed because it would be overwritten
|| (annoParam !== undefined))
{
var parameterName = param.name;
@@ -64,6 +79,12 @@ function(when, _) {
args[param.index] = req.body;
}
+ //handle @Callback
+ if (cb !== undefined)
+ {
+ args[param.index] = responseCallback;
+ }
+
}
return args;
}
@@ -89,7 +110,10 @@ function(when, _) {
res.json(result);
} else { //forwarding to view
if (typeof result === 'string')
- res.render(result + '.' + context.express_view);
+ if (result.lastIndexOf("redirect:", 0) === 0) //starts with 'redirect:'?
+ res.redirect(result.split(":")[1]);
+ else
+ res.render(result + '.' + context.express_view);
else if (result && result.view){
res.render(result.view + '.' + context.express_view, result.model);
}
View
13 yaap/wire/plugins/PostConstructProcessor.js
@@ -29,16 +29,17 @@ return {
processFunction: function(obj, fnDescription, annotationParams, context){
-
-
registeredInitializers.push({obj: obj, name: fnDescription.name});
},
afterProcessing: function(obj){
- while(registeredInitializers.length > 0){
- var init = registeredInitializers.pop();
- init.obj[init.name](); //call it
- }
+ for(var i = 0; i < registeredInitializers.length; ++i)
+ if (registeredInitializers[i].obj === obj)
+ {
+ var init = registeredInitializers.splice(i, 1)[0];
+ init.obj[init.name](); //call it
+ }
+
}
};
View
10 yaap/wire/plugins/PreDestroyProcessor.js
@@ -33,10 +33,12 @@ return {
},
beforeDestroying: function(obj){
- while(registeredDestroyers.length > 0){
- var init = registeredDestroyers.pop();
- init.obj[init.name](); //call it
- }
+ for(var i = 0; i < registeredInitializers.length; ++i)
+ if (registeredDestroyers[i].obj === obj)
+ {
+ var init = registeredDestroyers.splice(i, 1)[0];
+ init.obj[init.name](); //call it
+ }
}
};
View
2  yaap/yaap.js
@@ -78,7 +78,7 @@ function(_, registry, NotNullProcessor, DefaultProcessor, wire, PanPG_util, es5,
for(var f in obj)
{
- if (!_(obj[f]).isFunction()) return;
+ if (!_(obj[f]).isFunction()) continue;
var source = obj[f].toString();
source = source.substring(0, source.indexOf("{")); //strip body //TODO: this is not secure, if comments contain '{'
Please sign in to comment.
Something went wrong with that request. Please try again.