olivernn / davis.js

RESTful degradable JavaScript routing using pushState
http://davisjs.com
532 stars 58 forks source link

Tiny refactor + example #18

Closed tj closed 12 years ago

tj commented 12 years ago

added a tiny todo list example, and allowing Davis() as a short-cut to create an app. nice work man, pretty fun to use so far. I'm just going to poke around and send over any suggestions I can come up with while playing with examples

olivernn commented 12 years ago

Glad your enjoying it, and feel free to send through any suggestions or thoughts on the code.

Creating an app without passing in a function is a nice addition, certainly feels a lot closer to express, which is a Good Thing™.

tj commented 12 years ago

yup! so far so good. I did notice one thing that may be more of a gotcha than anything else, but if you POST and then navigate back, you'll get that POST again, so for the todo list you just keep adding items to the list while pressing back. I imagine it's the same for DELETE etc which could be a little weird

olivernn commented 12 years ago

I think the handling of non GET requests is correct, it matches what would happen on the server. If you do a POST and the server doesn't redirect then navigating with the back/forward buttons will re-submit the same request.

With Davis this is the same, if in your route handler you do not perform a redirect then the POST request will still be in the history, the preferred pattern is to redirect in your POST request handler

app.post('/foo', function (req) {
  // app logic here
  req.redirect('/bar')
})
tj commented 12 years ago

that's true, though a browser will (usually?) warn you, but maybe that's work a plugin should take care of