{"action":"created","comment":{"url":"https://api.github.com/repos/Shopify/twine/pulls/comments/67562493","id":67562493,"diff_hunk":"@@ -194,7 +203,7 @@ wrapFunctionString = (code, args, node) ->\n       ($context, $root) -> getValue($context, keypath)\n   else\n     try\n-      new Function(args, \"with($context) { return #{code} }\")\n+      new Function(args, \"with($context) { with($modules) { return #{code} } }\")","path":"lib/assets/javascripts/twine.js.coffee","position":28,"original_position":28,"commit_id":"d94fc845232cabfe310de7f27f4b48334ffaef96","original_commit_id":"d94fc845232cabfe310de7f27f4b48334ffaef96","user":{"login":"tsov","id":1802885,"avatar_url":"https://avatars.githubusercontent.com/u/1802885?v=3","gravatar_id":"","url":"https://api.github.com/users/tsov","html_url":"https://github.com/tsov","followers_url":"https://api.github.com/users/tsov/followers","following_url":"https://api.github.com/users/tsov/following{/other_user}","gists_url":"https://api.github.com/users/tsov/gists{/gist_id}","starred_url":"https://api.github.com/users/tsov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tsov/subscriptions","organizations_url":"https://api.github.com/users/tsov/orgs","repos_url":"https://api.github.com/users/tsov/repos","events_url":"https://api.github.com/users/tsov/events{/privacy}","received_events_url":"https://api.github.com/users/tsov/received_events","type":"User","site_admin":false},"body":"Ok, did some benchmarks and read some articles:\r\n\r\n### Performance pro & contra\r\n\r\n__Pro:__ The `with` statement can help reduce file size by reducing the need to repeat a lengthy object reference without performance penalty. The scope chain change required by 'with' _is not computationally expensive_. Use of `with` will _relieve the interpreter_ of parsing repeated object references. Note, however, that in many cases this benefit can be achieved by using a temporary variable to store a reference to the desired object.\r\n\r\n__Contra:__ The with statement forces the specified object to be searched first for all name lookups. Therefore all identifiers that aren't members of the specified object will be found more slowly in a `with` block. Where performance is important, `with` should only be used to encompass code blocks that access members of the specified object.\r\n\r\n----\r\n\r\n> `with` should only be used to encompass code blocks that access members of the specified object.\r\n\r\nI think this is the biggest take away ^ So we should use `with` conditionally, SO when using `define` or `eval` it wraps the nested `with` which includes `$modules` otherwise it remains as is\r\n\r\nSomething like?\r\n\r\n```coffee\r\n\"\"\"\r\nwith ($context) {\r\n  if (typeof $modules != 'undefined') {\r\n    with ($modules) {\r\n      return #{code}\r\n    }\r\n  } else {\r\n    return #{code}\r\n  }\r\n}\r\n\"\"\"\r\n```\r\n\r\nAny thoughts?","created_at":"2016-06-17T19:23:53Z","updated_at":"2016-06-17T19:23:53Z","html_url":"https://github.com/Shopify/twine/pull/74#discussion_r67562493","pull_request_url":"https://api.github.com/repos/Shopify/twine/pulls/74","_links":{"self":{"href":"https://api.github.com/repos/Shopify/twine/pulls/comments/67562493"},"html":{"href":"https://github.com/Shopify/twine/pull/74#discussion_r67562493"},"pull_request":{"href":"https://api.github.com/repos/Shopify/twine/pulls/74"}}},"pull_request":{"url":"https://api.github.com/repos/Shopify/twine/pulls/74","id":74147486,"html_url":"https://github.com/Shopify/twine/pull/74","diff_url":"https://github.com/Shopify/twine/pull/74.diff","patch_url":"https://github.com/Shopify/twine/pull/74.patch","issue_url":"https://api.github.com/repos/Shopify/twine/issues/74","number":74,"state":"open","locked":false,"title":"Adds Twine.register","user":{"login":"tsov","id":1802885,"avatar_url":"https://avatars.githubusercontent.com/u/1802885?v=3","gravatar_id":"","url":"https://api.github.com/users/tsov","html_url":"https://github.com/tsov","followers_url":"https://api.github.com/users/tsov/followers","following_url":"https://api.github.com/users/tsov/following{/other_user}","gists_url":"https://api.github.com/users/tsov/gists{/gist_id}","starred_url":"https://api.github.com/users/tsov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tsov/subscriptions","organizations_url":"https://api.github.com/users/tsov/orgs","repos_url":"https://api.github.com/users/tsov/repos","events_url":"https://api.github.com/users/tsov/events{/privacy}","received_events_url":"https://api.github.com/users/tsov/received_events","type":"User","site_admin":false},"body":"Twine currently relies on looking up modules/constructors within the global namespace (window style). There are multiple reasons why Twine should allow to register modules, constructors and/or functions.\r\n\r\nThis PR adds a public method `Twine.register(name, constructor)`, this allows us to register constructors with Twine without having to attach them to the global namespace, e.g. `window.MyModule`\r\n\r\n### Examples\r\n\r\n#### With classes\r\n\r\n```coffee\r\nclass MyModule\r\n  # ...\r\n\r\nTwine.register('MyModule', MyModule)\r\n```\r\n\r\n```html\r\n<div data-define=\"{myModule: new MyModule()}\">\r\n```\r\n\r\n#### With object literals\r\n\r\n```coffee\r\nTwine.register 'MyModule', {\r\n  fn: ->\r\n    # ...\r\n}\r\n```\r\n\r\n```html\r\n<div data-define=\"{myModule: MyModule.fn()}\">\r\n```\r\n\r\n#### With functions\r\n\r\n```coffee\r\nTwine.register 'MyFn', ->\r\n  # ...\r\n```\r\n\r\n```html\r\n<div data-define=\"{myModule: MyFn()}\">\r\n```\r\n\r\n@Shopify/tnt ","created_at":"2016-06-16T20:34:41Z","updated_at":"2016-06-17T19:23:53Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c4d15cc2a91dc214927a7802c34a214f6ff533b3","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Shopify/twine/pulls/74/commits","review_comments_url":"https://api.github.com/repos/Shopify/twine/pulls/74/comments","review_comment_url":"https://api.github.com/repos/Shopify/twine/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Shopify/twine/issues/74/comments","statuses_url":"https://api.github.com/repos/Shopify/twine/statuses/d94fc845232cabfe310de7f27f4b48334ffaef96","head":{"label":"Shopify:twine-register","ref":"twine-register","sha":"d94fc845232cabfe310de7f27f4b48334ffaef96","user":{"login":"Shopify","id":8085,"avatar_url":"https://avatars.githubusercontent.com/u/8085?v=3","gravatar_id":"","url":"https://api.github.com/users/Shopify","html_url":"https://github.com/Shopify","followers_url":"https://api.github.com/users/Shopify/followers","following_url":"https://api.github.com/users/Shopify/following{/other_user}","gists_url":"https://api.github.com/users/Shopify/gists{/gist_id}","starred_url":"https://api.github.com/users/Shopify/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Shopify/subscriptions","organizations_url":"https://api.github.com/users/Shopify/orgs","repos_url":"https://api.github.com/users/Shopify/repos","events_url":"https://api.github.com/users/Shopify/events{/privacy}","received_events_url":"https://api.github.com/users/Shopify/received_events","type":"Organization","site_admin":false},"repo":{"id":24009103,"name":"twine","full_name":"Shopify/twine","owner":{"login":"Shopify","id":8085,"avatar_url":"https://avatars.githubusercontent.com/u/8085?v=3","gravatar_id":"","url":"https://api.github.com/users/Shopify","html_url":"https://github.com/Shopify","followers_url":"https://api.github.com/users/Shopify/followers","following_url":"https://api.github.com/users/Shopify/following{/other_user}","gists_url":"https://api.github.com/users/Shopify/gists{/gist_id}","starred_url":"https://api.github.com/users/Shopify/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Shopify/subscriptions","organizations_url":"https://api.github.com/users/Shopify/orgs","repos_url":"https://api.github.com/users/Shopify/repos","events_url":"https://api.github.com/users/Shopify/events{/privacy}","received_events_url":"https://api.github.com/users/Shopify/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Shopify/twine","description":"Twine is a minimalistic two-way binding system","fork":false,"url":"https://api.github.com/repos/Shopify/twine","forks_url":"https://api.github.com/repos/Shopify/twine/forks","keys_url":"https://api.github.com/repos/Shopify/twine/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Shopify/twine/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Shopify/twine/teams","hooks_url":"https://api.github.com/repos/Shopify/twine/hooks","issue_events_url":"https://api.github.com/repos/Shopify/twine/issues/events{/number}","events_url":"https://api.github.com/repos/Shopify/twine/events","assignees_url":"https://api.github.com/repos/Shopify/twine/assignees{/user}","branches_url":"https://api.github.com/repos/Shopify/twine/branches{/branch}","tags_url":"https://api.github.com/repos/Shopify/twine/tags","blobs_url":"https://api.github.com/repos/Shopify/twine/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Shopify/twine/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Shopify/twine/git/refs{/sha}","trees_url":"https://api.github.com/repos/Shopify/twine/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Shopify/twine/statuses/{sha}","languages_url":"https://api.github.com/repos/Shopify/twine/languages","stargazers_url":"https://api.github.com/repos/Shopify/twine/stargazers","contributors_url":"https://api.github.com/repos/Shopify/twine/contributors","subscribers_url":"https://api.github.com/repos/Shopify/twine/subscribers","subscription_url":"https://api.github.com/repos/Shopify/twine/subscription","commits_url":"https://api.github.com/repos/Shopify/twine/commits{/sha}","git_commits_url":"https://api.github.com/repos/Shopify/twine/git/commits{/sha}","comments_url":"https://api.github.com/repos/Shopify/twine/comments{/number}","issue_comment_url":"https://api.github.com/repos/Shopify/twine/issues/comments{/number}","contents_url":"https://api.github.com/repos/Shopify/twine/contents/{+path}","compare_url":"https://api.github.com/repos/Shopify/twine/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Shopify/twine/merges","archive_url":"https://api.github.com/repos/Shopify/twine/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Shopify/twine/downloads","issues_url":"https://api.github.com/repos/Shopify/twine/issues{/number}","pulls_url":"https://api.github.com/repos/Shopify/twine/pulls{/number}","milestones_url":"https://api.github.com/repos/Shopify/twine/milestones{/number}","notifications_url":"https://api.github.com/repos/Shopify/twine/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Shopify/twine/labels{/name}","releases_url":"https://api.github.com/repos/Shopify/twine/releases{/id}","deployments_url":"https://api.github.com/repos/Shopify/twine/deployments","created_at":"2014-09-13T23:51:04Z","updated_at":"2016-06-16T17:40:03Z","pushed_at":"2016-06-17T18:14:25Z","git_url":"git://github.com/Shopify/twine.git","ssh_url":"git@github.com:Shopify/twine.git","clone_url":"https://github.com/Shopify/twine.git","svn_url":"https://github.com/Shopify/twine","homepage":"","size":251,"stargazers_count":64,"watchers_count":64,"language":"CoffeeScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":3,"mirror_url":null,"open_issues_count":20,"forks":3,"open_issues":20,"watchers":64,"default_branch":"master"}},"base":{"label":"Shopify:master","ref":"master","sha":"05369001231fcc25bf0784dd909e79592f8f988c","user":{"login":"Shopify","id":8085,"avatar_url":"https://avatars.githubusercontent.com/u/8085?v=3","gravatar_id":"","url":"https://api.github.com/users/Shopify","html_url":"https://github.com/Shopify","followers_url":"https://api.github.com/users/Shopify/followers","following_url":"https://api.github.com/users/Shopify/following{/other_user}","gists_url":"https://api.github.com/users/Shopify/gists{/gist_id}","starred_url":"https://api.github.com/users/Shopify/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Shopify/subscriptions","organizations_url":"https://api.github.com/users/Shopify/orgs","repos_url":"https://api.github.com/users/Shopify/repos","events_url":"https://api.github.com/users/Shopify/events{/privacy}","received_events_url":"https://api.github.com/users/Shopify/received_events","type":"Organization","site_admin":false},"repo":{"id":24009103,"name":"twine","full_name":"Shopify/twine","owner":{"login":"Shopify","id":8085,"avatar_url":"https://avatars.githubusercontent.com/u/8085?v=3","gravatar_id":"","url":"https://api.github.com/users/Shopify","html_url":"https://github.com/Shopify","followers_url":"https://api.github.com/users/Shopify/followers","following_url":"https://api.github.com/users/Shopify/following{/other_user}","gists_url":"https://api.github.com/users/Shopify/gists{/gist_id}","starred_url":"https://api.github.com/users/Shopify/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Shopify/subscriptions","organizations_url":"https://api.github.com/users/Shopify/orgs","repos_url":"https://api.github.com/users/Shopify/repos","events_url":"https://api.github.com/users/Shopify/events{/privacy}","received_events_url":"https://api.github.com/users/Shopify/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Shopify/twine","description":"Twine is a minimalistic two-way binding system","fork":false,"url":"https://api.github.com/repos/Shopify/twine","forks_url":"https://api.github.com/repos/Shopify/twine/forks","keys_url":"https://api.github.com/repos/Shopify/twine/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Shopify/twine/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Shopify/twine/teams","hooks_url":"https://api.github.com/repos/Shopify/twine/hooks","issue_events_url":"https://api.github.com/repos/Shopify/twine/issues/events{/number}","events_url":"https://api.github.com/repos/Shopify/twine/events","assignees_url":"https://api.github.com/repos/Shopify/twine/assignees{/user}","branches_url":"https://api.github.com/repos/Shopify/twine/branches{/branch}","tags_url":"https://api.github.com/repos/Shopify/twine/tags","blobs_url":"https://api.github.com/repos/Shopify/twine/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Shopify/twine/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Shopify/twine/git/refs{/sha}","trees_url":"https://api.github.com/repos/Shopify/twine/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Shopify/twine/statuses/{sha}","languages_url":"https://api.github.com/repos/Shopify/twine/languages","stargazers_url":"https://api.github.com/repos/Shopify/twine/stargazers","contributors_url":"https://api.github.com/repos/Shopify/twine/contributors","subscribers_url":"https://api.github.com/repos/Shopify/twine/subscribers","subscription_url":"https://api.github.com/repos/Shopify/twine/subscription","commits_url":"https://api.github.com/repos/Shopify/twine/commits{/sha}","git_commits_url":"https://api.github.com/repos/Shopify/twine/git/commits{/sha}","comments_url":"https://api.github.com/repos/Shopify/twine/comments{/number}","issue_comment_url":"https://api.github.com/repos/Shopify/twine/issues/comments{/number}","contents_url":"https://api.github.com/repos/Shopify/twine/contents/{+path}","compare_url":"https://api.github.com/repos/Shopify/twine/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Shopify/twine/merges","archive_url":"https://api.github.com/repos/Shopify/twine/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Shopify/twine/downloads","issues_url":"https://api.github.com/repos/Shopify/twine/issues{/number}","pulls_url":"https://api.github.com/repos/Shopify/twine/pulls{/number}","milestones_url":"https://api.github.com/repos/Shopify/twine/milestones{/number}","notifications_url":"https://api.github.com/repos/Shopify/twine/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Shopify/twine/labels{/name}","releases_url":"https://api.github.com/repos/Shopify/twine/releases{/id}","deployments_url":"https://api.github.com/repos/Shopify/twine/deployments","created_at":"2014-09-13T23:51:04Z","updated_at":"2016-06-16T17:40:03Z","pushed_at":"2016-06-17T18:14:25Z","git_url":"git://github.com/Shopify/twine.git","ssh_url":"git@github.com:Shopify/twine.git","clone_url":"https://github.com/Shopify/twine.git","svn_url":"https://github.com/Shopify/twine","homepage":"","size":251,"stargazers_count":64,"watchers_count":64,"language":"CoffeeScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":3,"mirror_url":null,"open_issues_count":20,"forks":3,"open_issues":20,"watchers":64,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Shopify/twine/pulls/74"},"html":{"href":"https://github.com/Shopify/twine/pull/74"},"issue":{"href":"https://api.github.com/repos/Shopify/twine/issues/74"},"comments":{"href":"https://api.github.com/repos/Shopify/twine/issues/74/comments"},"review_comments":{"href":"https://api.github.com/repos/Shopify/twine/pulls/74/comments"},"review_comment":{"href":"https://api.github.com/repos/Shopify/twine/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Shopify/twine/pulls/74/commits"},"statuses":{"href":"https://api.github.com/repos/Shopify/twine/statuses/d94fc845232cabfe310de7f27f4b48334ffaef96"}}}}
{"actor":{"display_login":"tsov"}}