{"action":"created","issue":{"url":"https://api.github.com/repos/meteor/meteor/issues/5577","repository_url":"https://api.github.com/repos/meteor/meteor","labels_url":"https://api.github.com/repos/meteor/meteor/issues/5577/labels{/name}","comments_url":"https://api.github.com/repos/meteor/meteor/issues/5577/comments","events_url":"https://api.github.com/repos/meteor/meteor/issues/5577/events","html_url":"https://github.com/meteor/meteor/issues/5577","id":114358569,"number":5577,"title":"Template instances should have \"lookup\" method","user":{"login":"mitar","id":585279,"avatar_url":"https://avatars.githubusercontent.com/u/585279?v=3","gravatar_id":"","url":"https://api.github.com/users/mitar","html_url":"https://github.com/mitar","followers_url":"https://api.github.com/users/mitar/followers","following_url":"https://api.github.com/users/mitar/following{/other_user}","gists_url":"https://api.github.com/users/mitar/gists{/gist_id}","starred_url":"https://api.github.com/users/mitar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mitar/subscriptions","organizations_url":"https://api.github.com/users/mitar/orgs","repos_url":"https://api.github.com/users/mitar/repos","events_url":"https://api.github.com/users/mitar/events{/privacy}","received_events_url":"https://api.github.com/users/mitar/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/meteor/meteor/labels/Project:Blaze","name":"Project:Blaze","color":"eb6420"},{"url":"https://api.github.com/repos/meteor/meteor/labels/Project:Blaze:Components","name":"Project:Blaze:Components","color":"5319e7"}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2015-10-30T21:23:31Z","updated_at":"2016-09-24T18:50:49Z","closed_at":"2016-09-24T18:50:49Z","body":"As discussed [here](https://github.com/meteor/guide/pull/75/files#r43528778), currently the issue is that it is hard to lookup symbols from code in the same way they are done in the templates. There are things like data context, lexical variables and so on.\r\n\r\nAdditionally, accessing data context registers dependency on the whole data context, even if you are accessing just a field.\r\n\r\nWe could implement this as a global template helper:\r\n\r\n```javascript\r\nTemplate.registerBoundHelper('lookup', function (name) {\r\n  const view = Template.instance().view;\r\n  var computedField = new ComputedField(function () {\r\n    var value = view.lookup(name);\r\n    if (_.isFunction(value)) {\r\n      value = value();\r\n    }\r\n    return value;\r\n  });\r\n  return computedField();\r\n});\r\n```\r\n\r\nOr template instance method:\r\n\r\n```javascript\r\nTemplateInstance.prototype.lookup = function (name) {\r\n  const self = this;\r\n  var computedField = new ComputedField(function () {\r\n    var value = self.view.lookup(name);\r\n    if (_.isFunction(value)) {\r\n      value = value();\r\n    }\r\n    return value;\r\n  });\r\n  return computedField();\r\n});\r\n```\r\n\r\nQuestion is what to do with symbol paths (`foo.bar`)."},"comment":{"url":"https://api.github.com/repos/meteor/meteor/issues/comments/249381105","html_url":"https://github.com/meteor/meteor/issues/5577#issuecomment-249381105","issue_url":"https://api.github.com/repos/meteor/meteor/issues/5577","id":249381105,"user":{"login":"mitar","id":585279,"avatar_url":"https://avatars.githubusercontent.com/u/585279?v=3","gravatar_id":"","url":"https://api.github.com/users/mitar","html_url":"https://github.com/mitar","followers_url":"https://api.github.com/users/mitar/followers","following_url":"https://api.github.com/users/mitar/following{/other_user}","gists_url":"https://api.github.com/users/mitar/gists{/gist_id}","starred_url":"https://api.github.com/users/mitar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mitar/subscriptions","organizations_url":"https://api.github.com/users/mitar/orgs","repos_url":"https://api.github.com/users/mitar/repos","events_url":"https://api.github.com/users/mitar/events{/privacy}","received_events_url":"https://api.github.com/users/mitar/received_events","type":"User","site_admin":false},"created_at":"2016-09-24T18:50:49Z","updated_at":"2016-09-24T18:50:49Z","body":"Closing in favor of https://github.com/meteor/blaze/issues/98."}}
{"actor":{"display_login":"mitar"}}