-
-
Save anonymous/de95b1d2e95da7a2fe3e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function ActionHandle() { | |
this.quux = 'quuz'; | |
} | |
function Router() { | |
var self = this; | |
var ROUTES = { | |
"GET": {}, | |
"POST": {}, | |
"PATCH": {}, | |
"DELETE": {} | |
}; | |
self.get = function(path, action, method){ | |
return compile_route_listing (path, action, method); | |
}; | |
// this is how I view the routing listings outside of the debugging call below | |
self.list = function(){ | |
console.dir(ROUTES); | |
}; | |
function compile_route_listing(path, action, method){ | |
var parts = action.split ("#"); // -> [controller, action] | |
var qualifier = new RegExp (path, "i"); | |
var handle = new ActionHandle (parts[0], parts[1]); | |
ROUTES[method][path] = { | |
"qualifier": qualifier, | |
"handle": handle | |
}; | |
console.dir(ROUTES); // debugging call, does same thing as self.list | |
return true; | |
} | |
} | |
var r = new Router(); | |
r.get('foo', 'bar#baz', 'POST'); | |
r.list(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment