Last active
August 29, 2015 14:24
-
-
Save floatdrop/a5f4cc79d160d0f09a87 to your computer and use it in GitHub Desktop.
Refactoring Tools!
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
// Disclaimer: пример намеренно упрощен | |
var app = express(); | |
app.get('/user/:id', function (req, res, next) { | |
if (req.params.id === '31337') { | |
res.send('Hello eleet!'); | |
return; | |
} | |
res.send('Hello user!'); | |
}); | |
// After refactoring | |
var app = express(); | |
function validate(req, res, next) { | |
if (req.params.id === '31337') { | |
res.send('Hello eleet!'); | |
return; | |
} | |
} | |
app.get('/user/:id', function (req, res, next) { | |
validate(req, res, next); | |
res.send('Hello user!'); // BOOM! 2 часа искали в коде | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment