{"action":"closed","issue":{"url":"https://api.github.com/repos/koajs/koa/issues/706","repository_url":"https://api.github.com/repos/koajs/koa","labels_url":"https://api.github.com/repos/koajs/koa/issues/706/labels{/name}","comments_url":"https://api.github.com/repos/koajs/koa/issues/706/comments","events_url":"https://api.github.com/repos/koajs/koa/issues/706/events","html_url":"https://github.com/koajs/koa/issues/706","id":146742001,"number":706,"title":"Automatic delegation","user":{"login":"PlasmaPower","id":6006498,"avatar_url":"https://avatars.githubusercontent.com/u/6006498?v=3","gravatar_id":"","url":"https://api.github.com/users/PlasmaPower","html_url":"https://github.com/PlasmaPower","followers_url":"https://api.github.com/users/PlasmaPower/followers","following_url":"https://api.github.com/users/PlasmaPower/following{/other_user}","gists_url":"https://api.github.com/users/PlasmaPower/gists{/gist_id}","starred_url":"https://api.github.com/users/PlasmaPower/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PlasmaPower/subscriptions","organizations_url":"https://api.github.com/users/PlasmaPower/orgs","repos_url":"https://api.github.com/users/PlasmaPower/repos","events_url":"https://api.github.com/users/PlasmaPower/events{/privacy}","received_events_url":"https://api.github.com/users/PlasmaPower/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/koajs/koa/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2016-04-07T21:06:27Z","updated_at":"2016-04-12T11:17:55Z","closed_at":"2016-04-12T11:17:55Z","body":"This was discussed over at tj/node-delegates#14 and we decided to merge the feature then discuss it's use here. It would replace [this](https://github.com/koajs/koa/blob/master/lib/context.js#L142) with this:\r\n\r\n```js\r\ndelegate.auto(proto, require('./request'), 'request');\r\ndelegate.auto(proto, require('./response'), 'response');\r\n\r\ndelegate(proto, 'request')\r\n  .method('get')\r\n  .method('is')\r\n  .getter('header')\r\n  .getter('headers')\r\n  .getter('socket');\r\n\r\ndelegate(proto, 'response')\r\n  .access('body')\r\n  .access('length')\r\n  .access('type');\r\n```\r\n\r\nThere are some conflicts, but we can keep the manual delegators for them as shown above. Since `__defineGetter__` (and defineSetter) set the configurable property to true, they can be overriden. This means we can automatically delegate most of the properties, and manually delegate what we need to override.\r\n\r\nNote that the response manual delegation isn't necessary since the second delegate.auto overrides the first one, but I think in conflicts it should be manually specified.\r\n\r\nOne problem I didn't think of is toJSON and inspect, both of which have implementations in request, response, and context. The context implementation is of course the wanted end result. We could manually define it afterwords, out of the class, although that would a bit hacky."}}