{"action":"created","comment":{"url":"https://api.github.com/repos/wayfair/tungstenjs/pulls/comments/75666799","id":75666799,"diff_hunk":"@@ -0,0 +1,138 @@\n+# Patterns in Tungsten.js Applications\n+\n+The following are some general patterns and principles for building Tungsten.js applications.  As with all patterns, there are exceptions and they are likely to change over time.  But these are generally good starting points when building an application.\n+\n+## Events up, methods down\n+\n+The most important principle for dealing with communciation between models in Tungsten.js is this: communication up the model tree should be done via events, communication down the model tree should be done by calling methods on the models.  Events up, methods down.\n+\n+What does this mean?  Suppose there are two models in a collection that need to communicate with one another.  Instead of the communication occuring directly between these two sibling models, the communication is going to go through their nearest ancestor, which in this case would be the parent model of the collection.  To do this, one model will trigger an event, e.g., `this.trigger('someEvent', data);` and the parent model will listen to that event and call a method on the second model to communicate the necessary information.  It will find which model in the collection to call the method on likely via a `collection.findWhere(attrs)` call.  Ideally the event and method should pass through only the information necessary for the communication and no more.  This is a simple case of events up, methods down for communicating between models, but it scales to more complex cases as well.","path":"docs/patterns.md","position":9,"original_position":9,"commit_id":"fb043f7e49abf808ce992050e0f8c4807f20d3e7","original_commit_id":"fb043f7e49abf808ce992050e0f8c4807f20d3e7","user":{"login":"danieluhl","id":1517899,"avatar_url":"https://avatars.githubusercontent.com/u/1517899?v=3","gravatar_id":"","url":"https://api.github.com/users/danieluhl","html_url":"https://github.com/danieluhl","followers_url":"https://api.github.com/users/danieluhl/followers","following_url":"https://api.github.com/users/danieluhl/following{/other_user}","gists_url":"https://api.github.com/users/danieluhl/gists{/gist_id}","starred_url":"https://api.github.com/users/danieluhl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danieluhl/subscriptions","organizations_url":"https://api.github.com/users/danieluhl/orgs","repos_url":"https://api.github.com/users/danieluhl/repos","events_url":"https://api.github.com/users/danieluhl/events{/privacy}","received_events_url":"https://api.github.com/users/danieluhl/received_events","type":"User","site_admin":false},"body":"Can we put an example of the scoped listenTo in here `this.listenTo(this.model, 'event:object:property', fn);` I find people often don't know about or have trouble finding documentation on this.","created_at":"2016-08-22T12:21:32Z","updated_at":"2016-08-22T12:21:32Z","html_url":"https://github.com/wayfair/tungstenjs/pull/259#discussion_r75666799","pull_request_url":"https://api.github.com/repos/wayfair/tungstenjs/pulls/259","_links":{"self":{"href":"https://api.github.com/repos/wayfair/tungstenjs/pulls/comments/75666799"},"html":{"href":"https://github.com/wayfair/tungstenjs/pull/259#discussion_r75666799"},"pull_request":{"href":"https://api.github.com/repos/wayfair/tungstenjs/pulls/259"}}},"pull_request":{"url":"https://api.github.com/repos/wayfair/tungstenjs/pulls/259","id":82175954,"html_url":"https://github.com/wayfair/tungstenjs/pull/259","diff_url":"https://github.com/wayfair/tungstenjs/pull/259.diff","patch_url":"https://github.com/wayfair/tungstenjs/pull/259.patch","issue_url":"https://api.github.com/repos/wayfair/tungstenjs/issues/259","number":259,"state":"open","locked":false,"title":"Tungsten.js Patterns Doc","user":{"login":"andrewrota","id":718017,"avatar_url":"https://avatars.githubusercontent.com/u/718017?v=3","gravatar_id":"","url":"https://api.github.com/users/andrewrota","html_url":"https://github.com/andrewrota","followers_url":"https://api.github.com/users/andrewrota/followers","following_url":"https://api.github.com/users/andrewrota/following{/other_user}","gists_url":"https://api.github.com/users/andrewrota/gists{/gist_id}","starred_url":"https://api.github.com/users/andrewrota/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andrewrota/subscriptions","organizations_url":"https://api.github.com/users/andrewrota/orgs","repos_url":"https://api.github.com/users/andrewrota/repos","events_url":"https://api.github.com/users/andrewrota/events{/privacy}","received_events_url":"https://api.github.com/users/andrewrota/received_events","type":"User","site_admin":false},"body":"# Overview\r\n\r\nA general doc on patterns (and anti-patterns) in tungsten.js applications.\r\n","created_at":"2016-08-22T11:38:28Z","updated_at":"2016-08-22T12:21:32Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a05c70f068f4d514ec5b9c3b3f2bccd809b6edec","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/wayfair/tungstenjs/pulls/259/commits","review_comments_url":"https://api.github.com/repos/wayfair/tungstenjs/pulls/259/comments","review_comment_url":"https://api.github.com/repos/wayfair/tungstenjs/pulls/comments{/number}","comments_url":"https://api.github.com/repos/wayfair/tungstenjs/issues/259/comments","statuses_url":"https://api.github.com/repos/wayfair/tungstenjs/statuses/fb043f7e49abf808ce992050e0f8c4807f20d3e7","head":{"label":"wayfair:patterns","ref":"patterns","sha":"fb043f7e49abf808ce992050e0f8c4807f20d3e7","user":{"login":"wayfair","id":1065892,"avatar_url":"https://avatars.githubusercontent.com/u/1065892?v=3","gravatar_id":"","url":"https://api.github.com/users/wayfair","html_url":"https://github.com/wayfair","followers_url":"https://api.github.com/users/wayfair/followers","following_url":"https://api.github.com/users/wayfair/following{/other_user}","gists_url":"https://api.github.com/users/wayfair/gists{/gist_id}","starred_url":"https://api.github.com/users/wayfair/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wayfair/subscriptions","organizations_url":"https://api.github.com/users/wayfair/orgs","repos_url":"https://api.github.com/users/wayfair/repos","events_url":"https://api.github.com/users/wayfair/events{/privacy}","received_events_url":"https://api.github.com/users/wayfair/received_events","type":"Organization","site_admin":false},"repo":{"id":32032028,"name":"tungstenjs","full_name":"wayfair/tungstenjs","owner":{"login":"wayfair","id":1065892,"avatar_url":"https://avatars.githubusercontent.com/u/1065892?v=3","gravatar_id":"","url":"https://api.github.com/users/wayfair","html_url":"https://github.com/wayfair","followers_url":"https://api.github.com/users/wayfair/followers","following_url":"https://api.github.com/users/wayfair/following{/other_user}","gists_url":"https://api.github.com/users/wayfair/gists{/gist_id}","starred_url":"https://api.github.com/users/wayfair/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wayfair/subscriptions","organizations_url":"https://api.github.com/users/wayfair/orgs","repos_url":"https://api.github.com/users/wayfair/repos","events_url":"https://api.github.com/users/wayfair/events{/privacy}","received_events_url":"https://api.github.com/users/wayfair/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/wayfair/tungstenjs","description":"","fork":false,"url":"https://api.github.com/repos/wayfair/tungstenjs","forks_url":"https://api.github.com/repos/wayfair/tungstenjs/forks","keys_url":"https://api.github.com/repos/wayfair/tungstenjs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/wayfair/tungstenjs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/wayfair/tungstenjs/teams","hooks_url":"https://api.github.com/repos/wayfair/tungstenjs/hooks","issue_events_url":"https://api.github.com/repos/wayfair/tungstenjs/issues/events{/number}","events_url":"https://api.github.com/repos/wayfair/tungstenjs/events","assignees_url":"https://api.github.com/repos/wayfair/tungstenjs/assignees{/user}","branches_url":"https://api.github.com/repos/wayfair/tungstenjs/branches{/branch}","tags_url":"https://api.github.com/repos/wayfair/tungstenjs/tags","blobs_url":"https://api.github.com/repos/wayfair/tungstenjs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/wayfair/tungstenjs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/wayfair/tungstenjs/git/refs{/sha}","trees_url":"https://api.github.com/repos/wayfair/tungstenjs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/wayfair/tungstenjs/statuses/{sha}","languages_url":"https://api.github.com/repos/wayfair/tungstenjs/languages","stargazers_url":"https://api.github.com/repos/wayfair/tungstenjs/stargazers","contributors_url":"https://api.github.com/repos/wayfair/tungstenjs/contributors","subscribers_url":"https://api.github.com/repos/wayfair/tungstenjs/subscribers","subscription_url":"https://api.github.com/repos/wayfair/tungstenjs/subscription","commits_url":"https://api.github.com/repos/wayfair/tungstenjs/commits{/sha}","git_commits_url":"https://api.github.com/repos/wayfair/tungstenjs/git/commits{/sha}","comments_url":"https://api.github.com/repos/wayfair/tungstenjs/comments{/number}","issue_comment_url":"https://api.github.com/repos/wayfair/tungstenjs/issues/comments{/number}","contents_url":"https://api.github.com/repos/wayfair/tungstenjs/contents/{+path}","compare_url":"https://api.github.com/repos/wayfair/tungstenjs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/wayfair/tungstenjs/merges","archive_url":"https://api.github.com/repos/wayfair/tungstenjs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/wayfair/tungstenjs/downloads","issues_url":"https://api.github.com/repos/wayfair/tungstenjs/issues{/number}","pulls_url":"https://api.github.com/repos/wayfair/tungstenjs/pulls{/number}","milestones_url":"https://api.github.com/repos/wayfair/tungstenjs/milestones{/number}","notifications_url":"https://api.github.com/repos/wayfair/tungstenjs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/wayfair/tungstenjs/labels{/name}","releases_url":"https://api.github.com/repos/wayfair/tungstenjs/releases{/id}","deployments_url":"https://api.github.com/repos/wayfair/tungstenjs/deployments","created_at":"2015-03-11T17:41:39Z","updated_at":"2016-08-10T19:49:20Z","pushed_at":"2016-08-22T11:40:17Z","git_url":"git://github.com/wayfair/tungstenjs.git","ssh_url":"git@github.com:wayfair/tungstenjs.git","clone_url":"https://github.com/wayfair/tungstenjs.git","svn_url":"https://github.com/wayfair/tungstenjs","homepage":null,"size":6441,"stargazers_count":170,"watchers_count":170,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":28,"mirror_url":null,"open_issues_count":19,"forks":28,"open_issues":19,"watchers":170,"default_branch":"master"}},"base":{"label":"wayfair:master","ref":"master","sha":"22acef9f7ff8415816c2a6691db9a78945dc4f35","user":{"login":"wayfair","id":1065892,"avatar_url":"https://avatars.githubusercontent.com/u/1065892?v=3","gravatar_id":"","url":"https://api.github.com/users/wayfair","html_url":"https://github.com/wayfair","followers_url":"https://api.github.com/users/wayfair/followers","following_url":"https://api.github.com/users/wayfair/following{/other_user}","gists_url":"https://api.github.com/users/wayfair/gists{/gist_id}","starred_url":"https://api.github.com/users/wayfair/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wayfair/subscriptions","organizations_url":"https://api.github.com/users/wayfair/orgs","repos_url":"https://api.github.com/users/wayfair/repos","events_url":"https://api.github.com/users/wayfair/events{/privacy}","received_events_url":"https://api.github.com/users/wayfair/received_events","type":"Organization","site_admin":false},"repo":{"id":32032028,"name":"tungstenjs","full_name":"wayfair/tungstenjs","owner":{"login":"wayfair","id":1065892,"avatar_url":"https://avatars.githubusercontent.com/u/1065892?v=3","gravatar_id":"","url":"https://api.github.com/users/wayfair","html_url":"https://github.com/wayfair","followers_url":"https://api.github.com/users/wayfair/followers","following_url":"https://api.github.com/users/wayfair/following{/other_user}","gists_url":"https://api.github.com/users/wayfair/gists{/gist_id}","starred_url":"https://api.github.com/users/wayfair/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wayfair/subscriptions","organizations_url":"https://api.github.com/users/wayfair/orgs","repos_url":"https://api.github.com/users/wayfair/repos","events_url":"https://api.github.com/users/wayfair/events{/privacy}","received_events_url":"https://api.github.com/users/wayfair/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/wayfair/tungstenjs","description":"","fork":false,"url":"https://api.github.com/repos/wayfair/tungstenjs","forks_url":"https://api.github.com/repos/wayfair/tungstenjs/forks","keys_url":"https://api.github.com/repos/wayfair/tungstenjs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/wayfair/tungstenjs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/wayfair/tungstenjs/teams","hooks_url":"https://api.github.com/repos/wayfair/tungstenjs/hooks","issue_events_url":"https://api.github.com/repos/wayfair/tungstenjs/issues/events{/number}","events_url":"https://api.github.com/repos/wayfair/tungstenjs/events","assignees_url":"https://api.github.com/repos/wayfair/tungstenjs/assignees{/user}","branches_url":"https://api.github.com/repos/wayfair/tungstenjs/branches{/branch}","tags_url":"https://api.github.com/repos/wayfair/tungstenjs/tags","blobs_url":"https://api.github.com/repos/wayfair/tungstenjs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/wayfair/tungstenjs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/wayfair/tungstenjs/git/refs{/sha}","trees_url":"https://api.github.com/repos/wayfair/tungstenjs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/wayfair/tungstenjs/statuses/{sha}","languages_url":"https://api.github.com/repos/wayfair/tungstenjs/languages","stargazers_url":"https://api.github.com/repos/wayfair/tungstenjs/stargazers","contributors_url":"https://api.github.com/repos/wayfair/tungstenjs/contributors","subscribers_url":"https://api.github.com/repos/wayfair/tungstenjs/subscribers","subscription_url":"https://api.github.com/repos/wayfair/tungstenjs/subscription","commits_url":"https://api.github.com/repos/wayfair/tungstenjs/commits{/sha}","git_commits_url":"https://api.github.com/repos/wayfair/tungstenjs/git/commits{/sha}","comments_url":"https://api.github.com/repos/wayfair/tungstenjs/comments{/number}","issue_comment_url":"https://api.github.com/repos/wayfair/tungstenjs/issues/comments{/number}","contents_url":"https://api.github.com/repos/wayfair/tungstenjs/contents/{+path}","compare_url":"https://api.github.com/repos/wayfair/tungstenjs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/wayfair/tungstenjs/merges","archive_url":"https://api.github.com/repos/wayfair/tungstenjs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/wayfair/tungstenjs/downloads","issues_url":"https://api.github.com/repos/wayfair/tungstenjs/issues{/number}","pulls_url":"https://api.github.com/repos/wayfair/tungstenjs/pulls{/number}","milestones_url":"https://api.github.com/repos/wayfair/tungstenjs/milestones{/number}","notifications_url":"https://api.github.com/repos/wayfair/tungstenjs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/wayfair/tungstenjs/labels{/name}","releases_url":"https://api.github.com/repos/wayfair/tungstenjs/releases{/id}","deployments_url":"https://api.github.com/repos/wayfair/tungstenjs/deployments","created_at":"2015-03-11T17:41:39Z","updated_at":"2016-08-10T19:49:20Z","pushed_at":"2016-08-22T11:40:17Z","git_url":"git://github.com/wayfair/tungstenjs.git","ssh_url":"git@github.com:wayfair/tungstenjs.git","clone_url":"https://github.com/wayfair/tungstenjs.git","svn_url":"https://github.com/wayfair/tungstenjs","homepage":null,"size":6441,"stargazers_count":170,"watchers_count":170,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":28,"mirror_url":null,"open_issues_count":19,"forks":28,"open_issues":19,"watchers":170,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/wayfair/tungstenjs/pulls/259"},"html":{"href":"https://github.com/wayfair/tungstenjs/pull/259"},"issue":{"href":"https://api.github.com/repos/wayfair/tungstenjs/issues/259"},"comments":{"href":"https://api.github.com/repos/wayfair/tungstenjs/issues/259/comments"},"review_comments":{"href":"https://api.github.com/repos/wayfair/tungstenjs/pulls/259/comments"},"review_comment":{"href":"https://api.github.com/repos/wayfair/tungstenjs/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/wayfair/tungstenjs/pulls/259/commits"},"statuses":{"href":"https://api.github.com/repos/wayfair/tungstenjs/statuses/fb043f7e49abf808ce992050e0f8c4807f20d3e7"}}}}
{"actor":{"display_login":"danieluhl"}}