facn2 / ApolloXII

Autocomplete Widget
1 stars 0 forks source link

Router/handler #48

Closed m4v15 closed 7 years ago

m4v15 commented 7 years ago

Again, nice start to modularisation and seperation of concerns, but could be improved.

All the router should do is pass the (req, res) onto a handler, and then the handler does everything with it. So you have

router = (req, res) => {
if (option1) 
    handler1(req,res)
if (option2) 
    handler2(req,res)
}

Everything you need is within those request and response arguments. This then is much neater, easier to read and easier to replicate.

If for example, one person writes the router, they can always pass the (req,res) arguments to every handler, and then whoever is making the handlers will always know to make a function with those two arguments

rinoma commented 7 years ago

Done