knockout.model
knockout.model copied to clipboard
afterHooks doesn't work with routeName as expected from example
In the example, you show urls being mapped to names like "show" and "create". You then demonstrate the use of __afterHooks by mapping a function to "create". So I would expect that when a call is made to create, that hook would fire, but it wouldn't because the following sequence of events takes place:
this.createcallsthis.doPost("create", params, callback)where"create"is mapped to the argumentrouteNamerouteName, since it doesn't containhttp, is used to get a url from__urls- This url is then passed to the static
doPostmapped to itsrouteNameargument, so whererouteNamewas a string like"create"before, it's now a url - When the static
doPostgets to the part where it checksah[routeName], becauserouteNameis now a url, it doesn't find a match. The "create" afterHook would never be fired, unless the original call tocreatewas a static call, not an instance call. The same would go for any other hook that was registered to match a key in__urls.
I think the solution is as simple as removing
if (routeName.match(/^http:\/\//) === null) {
url = this.__urls[routeName];
} else {
url = routeName;
}
from the prototype version of doGet and doPost since it will always eventually call the static version, where the url will be looked up. I say I think it's that simple because I haven't thought about possible side effects.