GitHub PullRequestReviewCommentEvent at 2014-05-25 11:14:07
Repository: ithank
Actor: oleggromov
Payload: {"comment":{"url":"https://api.github.com/repos/oleggromov/ithank/pulls/comments/13030298","id":13030298,"diff_hunk":"@@ -41,6 +29,19 @@ app.use(app.router);\n app.get('/', require('controllers/main'));\n app.get('/:id', require('controllers/getThank'));\n \n+app.use(function(req, res) {\n+\tvar isError = req.state.status === 'error';\n+\n+\tif (req.isAjax) {\n+\t\tres.json(req.state);\n+\t}\n+\tif (isError && !req.isAjax) {\n+\t\tres.send(req.state.code);\n+\t}\n+\tif (!isError && !req.isAjax) {\n+\t\tres.render('index', req.state.data);\n+\t}","path":"server/app.js","position":57,"original_position":57,"commit_id":"9fc1bd4f70819a9660d8404bc143b66e2084f6e8","original_commit_id":"9fc1bd4f70819a9660d8404bc143b66e2084f6e8","user":{"login":"oleggromov","id":2196347,"avatar_url":"https://avatars.githubusercontent.com/u/2196347?","gravatar_id":"98b6f99905a8d560482c84ec9041d669","url":"https://api.github.com/users/oleggromov","html_url":"https://github.com/oleggromov","followers_url":"https://api.github.com/users/oleggromov/followers","following_url":"https://api.github.com/users/oleggromov/following{/other_user}","gists_url":"https://api.github.com/users/oleggromov/gists{/gist_id}","starred_url":"https://api.github.com/users/oleggromov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/oleggromov/subscriptions","organizations_url":"https://api.github.com/users/oleggromov/orgs","repos_url":"https://api.github.com/users/oleggromov/repos","events_url":"https://api.github.com/users/oleggromov/events{/privacy}","received_events_url":"https://api.github.com/users/oleggromov/received_events","type":"User","site_admin":false},"body":"Я бы переписал:\r\n```js\r\nif (req.isAjax) {\r\n\tres.json(req.state);\r\n} else {\r\n\tif (req.state.status === 'error') {\r\n\t\tres.send(req.state.code);\r\n\t} else {\r\n\t\tres.render('index', req.state.data);\t\r\n\t}\r\n}\r\n```\r\n\r\nНе понятно:\r\n* `req.state` как будто бы должен называться `res.result`;\r\n* какие ещё значения бывают у `status`?\r\n* я бы добавил параметр `result.page`, означающий имя шаблона — тогда каждый контроллер сможет задавать свои данные и шаблон, а эта мидлварь будет всё рендерить.","created_at":"2014-05-25T11:14:07Z","updated_at":"2014-05-25T11:14:07Z","html_url":"https://github.com/oleggromov/ithank/pull/10#discussion_r13030298","pull_request_url":"https://api.github.com/repos/oleggromov/ithank/pulls/10","_links":{"self":{"href":"https://api.github.com/repos/oleggromov/ithank/pulls/comments/13030298"},"html":{"href":"https://github.com/oleggromov/ithank/pull/10#discussion_r13030298"},"pull_request":{"href":"https://api.github.com/repos/oleggromov/ithank/pulls/10"}}}}