Comparing version 3.0.1 to 3.1.0
@@ -10,3 +10,3 @@ 'use strict'; | ||
function createMatcher(method, strings, dynamicSegments, onMatch, context) { | ||
function createMatcher(method, strings, dynamicSegments, onMatch) { | ||
const staticSegments = strings.map(function(str) { | ||
@@ -56,3 +56,3 @@ return str.split('/').filter(nonEmpty); | ||
routeArgsByReq.set(req, args); | ||
return onMatch.apply(context, [ req ].concat(args)); | ||
return onMatch.apply(this, [ req ].concat(args)); | ||
} | ||
@@ -86,4 +86,13 @@ | ||
const params = [].slice.call(arguments, 1); | ||
return function(onMatch) { | ||
return createMatcher(method, strings, params, onMatch, null); | ||
return function(target, propName, descriptor) { | ||
if (arguments.length === 1) { // we just decorate a function | ||
return createMatcher(method, strings, params, target); | ||
} else if (arguments.length === 3) { | ||
return { | ||
enumberable: descriptor.enumberable, | ||
configurable: descriptor.configurable, | ||
writeable: descriptor.writeable, | ||
value: createMatcher(method, strings, params, descriptor.value) | ||
} | ||
} | ||
}; | ||
@@ -90,0 +99,0 @@ }; |
{ | ||
"name": "wegweiser", | ||
"version": "3.0.1", | ||
"version": "3.1.0", | ||
"description": "A router for Quinn", | ||
@@ -5,0 +5,0 @@ "main": "wegweiser.js", |
@@ -6,5 +6,20 @@ # Wegweiser | ||
```js | ||
const app = GET `/my/scope` (req => { | ||
const simpleHandler = GET `/my/scope` (req => { | ||
return respond().body('ok'); | ||
}); | ||
const usingDecorators = { | ||
@GET `/add/${Number}/${Number}` | ||
getSum(req, a, b) { | ||
return respond().body(`${a} + ${b} = ${a + b}`); | ||
} | ||
}; | ||
class PretendingItsJava { | ||
@PUT `/user/${String}/profile` | ||
async updateProfile(req, username) { | ||
const data = await readJson(req); | ||
return respond.json({ ok: true, firstName: data.firstName }); | ||
} | ||
} | ||
``` |
4132
87
25