GitHub PullRequestReviewCommentEvent at 2014-08-20 22:13:19
Repository: data
Actor: stefanpenner
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/emberjs/data/pulls/comments/16509483","id":16509483,"diff_hunk":"@@ -0,0 +1,264 @@\n+import { PromiseArray, PromiseObject } from \"ember-data/system/promise_proxies\";\n+\n+var Relationship = function(store, record, inverseKey, relationshipMeta) {\n+  this.members = new Ember.OrderedSet();\n+  this.store = store;\n+  this.key = relationshipMeta.key;\n+  this.inverseKey = inverseKey;\n+  this.record = record;\n+  this.key = relationshipMeta.key;\n+  this.isAsync = relationshipMeta.options.async;\n+  this.relationshipMeta = relationshipMeta;\n+};\n+\n+Relationship.prototype = {\n+  constructor: Relationship,\n+  hasFetchedLink: false,\n+\n+  destroy: Ember.K,\n+\n+  clear: function() {\n+    this.members.forEach(function(member) {\n+      this.removeRecord(member);\n+    }, this);\n+  },\n+\n+  computeChanges: function(records) {\n+     var  members = this.members;\n+\n+    records = setForArray(records);\n+\n+    //TODO(Igor) add order preserving logic\n+    records.forEach(function(record) {\n+      if (members.has(record)) return;\n+      this.addRecord(record);\n+    }, this);\n+\n+    members.forEach(function(member) {\n+      if (records.has(member)) return;\n+      this.removeRecord(member);\n+    }, this);\n+  },\n+\n+  removeRecords: function(records){\n+    var that = this;\n+    records.forEach(function(record){\n+      that.removeRecord(record);\n+    });\n+  },\n+\n+  addRecords: function(records, idx){\n+    var that = this;\n+    records.forEach(function(record){\n+      that.addRecord(record, idx);\n+      if (idx !== undefined) {\n+        idx++;\n+      }\n+    });\n+  },\n+\n+\n+  addRecord: function(record, idx) {\n+    if (!this.members.has(record)) {\n+      this.members.add(record);\n+      this.notifyRecordRelationshipAdded(record, idx);\n+      if (this.inverseKey) {\n+        record._relationships[this.inverseKey].addRecord(this.record);\n+      }\n+    }\n+  },\n+\n+  removeRecord: function(record) {\n+    if (this.members.has(record)) {\n+      this.members.remove(record);\n+      this.notifyRecordRelationshipRemoved(record);\n+      if (this.inverseKey) {\n+        var inverseRelationship = record._relationships[this.inverseKey];\n+        //Need to check for existence, as the record might unloading at the moment\n+        if (inverseRelationship) {\n+          inverseRelationship.removeRecord(this.record);\n+        }\n+      }\n+    }\n+  },\n+\n+  updateLink: function(link) {\n+    if (link !== this.link) {\n+      this.link = link;\n+      this.hasFetchedLink = false;\n+      this.record.notifyPropertyChange(this.key);\n+    }\n+  },\n+\n+  updateRecordsFromServer: function(records) {\n+    //TODO Keep the newlyCreated records\n+    //TODO(Igor) Think about the ordering\n+    var delta = this.computeChanges(records);\n+  }\n+};\n+\n+var ManyRelationship = function(store, record, inverseKey, relationshipMeta) {\n+  Relationship.apply(this, arguments);\n+  this.belongsToType = relationshipMeta.type;\n+  this.manyArray = store.recordArrayManager.createManyArray(this.belongsToType, Ember.A());\n+  this.manyArray.relationship = this;\n+  this.isPolymorphic = relationshipMeta.options.polymorphic;\n+  this.manyArray.isPolymorphic = this.isPolymorphic;\n+};\n+\n+ManyRelationship.prototype = Object.create(Relationship.prototype);\n+\n+ManyRelationship.prototype.constructor = ManyRelationship;\n+ManyRelationship.prototype.destroy = function() {\n+  this.manyArray.destroy();\n+};\n+\n+ManyRelationship.prototype.notifyRecordRelationshipAdded = function(record, idx) {\n+  Ember.assert(\"You cannot add '\" + record.constructor.typeKey + \"' records to this relationship (only '\" + this.belongsToType.typeKey + \"' allowed)\", !this.belongsToType || record instanceof this.belongsToType);\n+  this.record.notifyHasManyAdded(this.key, record, idx);\n+};\n+\n+ManyRelationship.prototype.notifyRecordRelationshipRemoved = function(record) {\n+  this.record.notifyHasManyRemoved(this.key, record);\n+};\n+\n+ManyRelationship.prototype.getValue = function() {\n+  if (this.isAsync) {\n+    var self = this;\n+    var promise;\n+    if (this.link && !this.hasFetchedLink) {\n+      promise = this.store.findHasMany(this.record, this.link, this.belongsToType).then(function(records){\n+        self.updateRecordsFromServer(records);\n+        self.hasFetchedLink = true;\n+        //TODO(Igor) try to abstract the isLoaded part\n+        self.manyArray.set('isLoaded', true);\n+        return self.manyArray;\n+      });\n+    } else {\n+      var manyArray = this.manyArray;\n+      promise = this.store.findMany(manyArray.toArray()).then(function(){\n+        self.manyArray.set('isLoaded', true);\n+        return manyArray;\n+      });\n+    }\n+    return PromiseArray.create({\n+      promise: promise\n+    });\n+  } else {\n+    this.manyArray.set('isLoaded', true);\n+    return this.manyArray;\n+ }\n+};\n+\n+var BelongsToRelationship = function(store, record, inverseKey, relationshipMeta) {\n+  Relationship.apply(this, arguments);\n+  this.members.add(record);\n+  this.record = record;\n+  this.key = relationshipMeta.key;\n+  this.inverseKey = inverseKey;\n+  this.inverseRecord = null;\n+};\n+\n+BelongsToRelationship.prototype = Object.create(Relationship.prototype);\n+ManyRelationship.prototype.constructor = BelongsToRelationship;\n+\n+BelongsToRelationship.prototype.setRecord = function(newRecord) {\n+  if (newRecord) {\n+    this.addRecord(newRecord);\n+  } else if (this.inverseRecord) {\n+    this.removeRecord(this.inverseRecord);\n+  }\n+};\n+\n+BelongsToRelationship.prototype.addRecord = function(newRecord) {\n+  if (this.members.has(newRecord)){ return;}","path":"packages/ember-data/lib/system/relationships/relationship.js","position":174,"original_position":174,"commit_id":"029b769b39f04fdcf6dd53f3c54ac78fbc45ac63","original_commit_id":"029b769b39f04fdcf6dd53f3c54ac78fbc45ac63","user":{"login":"stefanpenner","id":1377,"avatar_url":"https://avatars.githubusercontent.com/u/1377?v=2","gravatar_id":"8ccebbc3d28f903d5c214efd3447ac71","url":"https://api.github.com/users/stefanpenner","html_url":"https://github.com/stefanpenner","followers_url":"https://api.github.com/users/stefanpenner/followers","following_url":"https://api.github.com/users/stefanpenner/following{/other_user}","gists_url":"https://api.github.com/users/stefanpenner/gists{/gist_id}","starred_url":"https://api.github.com/users/stefanpenner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stefanpenner/subscriptions","organizations_url":"https://api.github.com/users/stefanpenner/orgs","repos_url":"https://api.github.com/users/stefanpenner/repos","events_url":"https://api.github.com/users/stefanpenner/events{/privacy}","received_events_url":"https://api.github.com/users/stefanpenner/received_events","type":"User","site_admin":false},"body":"maybe Relationship needs `has` method itself rather then constantly having to call this.members.has","created_at":"2014-08-20T22:13:19Z","updated_at":"2014-08-20T22:13:19Z","html_url":"https://github.com/emberjs/data/pull/2208#discussion_r16509483","pull_request_url":"https://api.github.com/repos/emberjs/data/pulls/2208","_links":{"self":{"href":"https://api.github.com/repos/emberjs/data/pulls/comments/16509483"},"html":{"href":"https://github.com/emberjs/data/pull/2208#discussion_r16509483"},"pull_request":{"href":"https://api.github.com/repos/emberjs/data/pulls/2208"}}},"pull_request":{"url":"https://api.github.com/repos/emberjs/data/pulls/2208","id":20059677,"html_url":"https://github.com/emberjs/data/pull/2208","diff_url":"https://github.com/emberjs/data/pull/2208.diff","patch_url":"https://github.com/emberjs/data/pull/2208.patch","issue_url":"https://api.github.com/repos/emberjs/data/issues/2208","number":2208,"state":"open","locked":false,"title":"Sync ssot","user":{"login":"igorT","id":715175,"avatar_url":"https://avatars.githubusercontent.com/u/715175?v=2","gravatar_id":"afe2956934debbbaac1049307b71278f","url":"https://api.github.com/users/igorT","html_url":"https://github.com/igorT","followers_url":"https://api.github.com/users/igorT/followers","following_url":"https://api.github.com/users/igorT/following{/other_user}","gists_url":"https://api.github.com/users/igorT/gists{/gist_id}","starred_url":"https://api.github.com/users/igorT/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/igorT/subscriptions","organizations_url":"https://api.github.com/users/igorT/orgs","repos_url":"https://api.github.com/users/igorT/repos","events_url":"https://api.github.com/users/igorT/events{/privacy}","received_events_url":"https://api.github.com/users/igorT/received_events","type":"User","site_admin":false},"body":"Placeholder, needs more tests and comments. \r\nFixes #1919 #1814 #2057 #2191 #2177 #2125 #2100 #1848 #1790 #1532 #1389 #1308\r\n","created_at":"2014-08-20T17:19:12Z","updated_at":"2014-08-20T22:13:19Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3bf43f5cd80d8b1dd6a97187f90f3ae488a692ba","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/emberjs/data/pulls/2208/commits","review_comments_url":"https://api.github.com/repos/emberjs/data/pulls/2208/comments","review_comment_url":"https://api.github.com/repos/emberjs/data/pulls/comments/{number}","comments_url":"https://api.github.com/repos/emberjs/data/issues/2208/comments","statuses_url":"https://api.github.com/repos/emberjs/data/statuses/029b769b39f04fdcf6dd53f3c54ac78fbc45ac63","head":{"label":"emberjs:sync_ssot","ref":"sync_ssot","sha":"029b769b39f04fdcf6dd53f3c54ac78fbc45ac63","user":{"login":"emberjs","id":1253363,"avatar_url":"https://avatars.githubusercontent.com/u/1253363?v=2","gravatar_id":"792333d2bad390e8a2e23f5e2f41f214","url":"https://api.github.com/users/emberjs","html_url":"https://github.com/emberjs","followers_url":"https://api.github.com/users/emberjs/followers","following_url":"https://api.github.com/users/emberjs/following{/other_user}","gists_url":"https://api.github.com/users/emberjs/gists{/gist_id}","starred_url":"https://api.github.com/users/emberjs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/emberjs/subscriptions","organizations_url":"https://api.github.com/users/emberjs/orgs","repos_url":"https://api.github.com/users/emberjs/repos","events_url":"https://api.github.com/users/emberjs/events{/privacy}","received_events_url":"https://api.github.com/users/emberjs/received_events","type":"Organization","site_admin":false},"repo":{"id":3016562,"name":"data","full_name":"emberjs/data","owner":{"login":"emberjs","id":1253363,"avatar_url":"https://avatars.githubusercontent.com/u/1253363?v=2","gravatar_id":"792333d2bad390e8a2e23f5e2f41f214","url":"https://api.github.com/users/emberjs","html_url":"https://github.com/emberjs","followers_url":"https://api.github.com/users/emberjs/followers","following_url":"https://api.github.com/users/emberjs/following{/other_user}","gists_url":"https://api.github.com/users/emberjs/gists{/gist_id}","starred_url":"https://api.github.com/users/emberjs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/emberjs/subscriptions","organizations_url":"https://api.github.com/users/emberjs/orgs","repos_url":"https://api.github.com/users/emberjs/repos","events_url":"https://api.github.com/users/emberjs/events{/privacy}","received_events_url":"https://api.github.com/users/emberjs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/emberjs/data","description":"A data persistence library for Ember.js.","fork":false,"url":"https://api.github.com/repos/emberjs/data","forks_url":"https://api.github.com/repos/emberjs/data/forks","keys_url":"https://api.github.com/repos/emberjs/data/keys{/key_id}","collaborators_url":"https://api.github.com/repos/emberjs/data/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/emberjs/data/teams","hooks_url":"https://api.github.com/repos/emberjs/data/hooks","issue_events_url":"https://api.github.com/repos/emberjs/data/issues/events{/number}","events_url":"https://api.github.com/repos/emberjs/data/events","assignees_url":"https://api.github.com/repos/emberjs/data/assignees{/user}","branches_url":"https://api.github.com/repos/emberjs/data/branches{/branch}","tags_url":"https://api.github.com/repos/emberjs/data/tags","blobs_url":"https://api.github.com/repos/emberjs/data/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/emberjs/data/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/emberjs/data/git/refs{/sha}","trees_url":"https://api.github.com/repos/emberjs/data/git/trees{/sha}","statuses_url":"https://api.github.com/repos/emberjs/data/statuses/{sha}","languages_url":"https://api.github.com/repos/emberjs/data/languages","stargazers_url":"https://api.github.com/repos/emberjs/data/stargazers","contributors_url":"https://api.github.com/repos/emberjs/data/contributors","subscribers_url":"https://api.github.com/repos/emberjs/data/subscribers","subscription_url":"https://api.github.com/repos/emberjs/data/subscription","commits_url":"https://api.github.com/repos/emberjs/data/commits{/sha}","git_commits_url":"https://api.github.com/repos/emberjs/data/git/commits{/sha}","comments_url":"https://api.github.com/repos/emberjs/data/comments{/number}","issue_comment_url":"https://api.github.com/repos/emberjs/data/issues/comments/{number}","contents_url":"https://api.github.com/repos/emberjs/data/contents/{+path}","compare_url":"https://api.github.com/repos/emberjs/data/compare/{base}...{head}","merges_url":"https://api.github.com/repos/emberjs/data/merges","archive_url":"https://api.github.com/repos/emberjs/data/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/emberjs/data/downloads","issues_url":"https://api.github.com/repos/emberjs/data/issues{/number}","pulls_url":"https://api.github.com/repos/emberjs/data/pulls{/number}","milestones_url":"https://api.github.com/repos/emberjs/data/milestones{/number}","notifications_url":"https://api.github.com/repos/emberjs/data/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/emberjs/data/labels{/name}","releases_url":"https://api.github.com/repos/emberjs/data/releases{/id}","created_at":"2011-12-20T01:50:40Z","updated_at":"2014-08-20T01:01:04Z","pushed_at":"2014-08-20T20:35:24Z","git_url":"git://github.com/emberjs/data.git","ssh_url":"git@github.com:emberjs/data.git","clone_url":"https://github.com/emberjs/data.git","svn_url":"https://github.com/emberjs/data","homepage":"","size":21627,"stargazers_count":1975,"watchers_count":1975,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"forks_count":734,"mirror_url":null,"open_issues_count":197,"forks":734,"open_issues":197,"watchers":1975,"default_branch":"master"}},"base":{"label":"emberjs:master","ref":"master","sha":"4c2780149f326fe4634b8d68ecfe996ddb7481b4","user":{"login":"emberjs","id":1253363,"avatar_url":"https://avatars.githubusercontent.com/u/1253363?v=2","gravatar_id":"792333d2bad390e8a2e23f5e2f41f214","url":"https://api.github.com/users/emberjs","html_url":"https://github.com/emberjs","followers_url":"https://api.github.com/users/emberjs/followers","following_url":"https://api.github.com/users/emberjs/following{/other_user}","gists_url":"https://api.github.com/users/emberjs/gists{/gist_id}","starred_url":"https://api.github.com/users/emberjs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/emberjs/subscriptions","organizations_url":"https://api.github.com/users/emberjs/orgs","repos_url":"https://api.github.com/users/emberjs/repos","events_url":"https://api.github.com/users/emberjs/events{/privacy}","received_events_url":"https://api.github.com/users/emberjs/received_events","type":"Organization","site_admin":false},"repo":{"id":3016562,"name":"data","full_name":"emberjs/data","owner":{"login":"emberjs","id":1253363,"avatar_url":"https://avatars.githubusercontent.com/u/1253363?v=2","gravatar_id":"792333d2bad390e8a2e23f5e2f41f214","url":"https://api.github.com/users/emberjs","html_url":"https://github.com/emberjs","followers_url":"https://api.github.com/users/emberjs/followers","following_url":"https://api.github.com/users/emberjs/following{/other_user}","gists_url":"https://api.github.com/users/emberjs/gists{/gist_id}","starred_url":"https://api.github.com/users/emberjs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/emberjs/subscriptions","organizations_url":"https://api.github.com/users/emberjs/orgs","repos_url":"https://api.github.com/users/emberjs/repos","events_url":"https://api.github.com/users/emberjs/events{/privacy}","received_events_url":"https://api.github.com/users/emberjs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/emberjs/data","description":"A data persistence library for Ember.js.","fork":false,"url":"https://api.github.com/repos/emberjs/data","forks_url":"https://api.github.com/repos/emberjs/data/forks","keys_url":"https://api.github.com/repos/emberjs/data/keys{/key_id}","collaborators_url":"https://api.github.com/repos/emberjs/data/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/emberjs/data/teams","hooks_url":"https://api.github.com/repos/emberjs/data/hooks","issue_events_url":"https://api.github.com/repos/emberjs/data/issues/events{/number}","events_url":"https://api.github.com/repos/emberjs/data/events","assignees_url":"https://api.github.com/repos/emberjs/data/assignees{/user}","branches_url":"https://api.github.com/repos/emberjs/data/branches{/branch}","tags_url":"https://api.github.com/repos/emberjs/data/tags","blobs_url":"https://api.github.com/repos/emberjs/data/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/emberjs/data/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/emberjs/data/git/refs{/sha}","trees_url":"https://api.github.com/repos/emberjs/data/git/trees{/sha}","statuses_url":"https://api.github.com/repos/emberjs/data/statuses/{sha}","languages_url":"https://api.github.com/repos/emberjs/data/languages","stargazers_url":"https://api.github.com/repos/emberjs/data/stargazers","contributors_url":"https://api.github.com/repos/emberjs/data/contributors","subscribers_url":"https://api.github.com/repos/emberjs/data/subscribers","subscription_url":"https://api.github.com/repos/emberjs/data/subscription","commits_url":"https://api.github.com/repos/emberjs/data/commits{/sha}","git_commits_url":"https://api.github.com/repos/emberjs/data/git/commits{/sha}","comments_url":"https://api.github.com/repos/emberjs/data/comments{/number}","issue_comment_url":"https://api.github.com/repos/emberjs/data/issues/comments/{number}","contents_url":"https://api.github.com/repos/emberjs/data/contents/{+path}","compare_url":"https://api.github.com/repos/emberjs/data/compare/{base}...{head}","merges_url":"https://api.github.com/repos/emberjs/data/merges","archive_url":"https://api.github.com/repos/emberjs/data/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/emberjs/data/downloads","issues_url":"https://api.github.com/repos/emberjs/data/issues{/number}","pulls_url":"https://api.github.com/repos/emberjs/data/pulls{/number}","milestones_url":"https://api.github.com/repos/emberjs/data/milestones{/number}","notifications_url":"https://api.github.com/repos/emberjs/data/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/emberjs/data/labels{/name}","releases_url":"https://api.github.com/repos/emberjs/data/releases{/id}","created_at":"2011-12-20T01:50:40Z","updated_at":"2014-08-20T01:01:04Z","pushed_at":"2014-08-20T20:35:24Z","git_url":"git://github.com/emberjs/data.git","ssh_url":"git@github.com:emberjs/data.git","clone_url":"https://github.com/emberjs/data.git","svn_url":"https://github.com/emberjs/data","homepage":"","size":21627,"stargazers_count":1975,"watchers_count":1975,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"forks_count":734,"mirror_url":null,"open_issues_count":197,"forks":734,"open_issues":197,"watchers":1975,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/emberjs/data/pulls/2208"},"html":{"href":"https://github.com/emberjs/data/pull/2208"},"issue":{"href":"https://api.github.com/repos/emberjs/data/issues/2208"},"comments":{"href":"https://api.github.com/repos/emberjs/data/issues/2208/comments"},"review_comments":{"href":"https://api.github.com/repos/emberjs/data/pulls/2208/comments"},"review_comment":{"href":"https://api.github.com/repos/emberjs/data/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/emberjs/data/pulls/2208/commits"},"statuses":{"href":"https://api.github.com/repos/emberjs/data/statuses/029b769b39f04fdcf6dd53f3c54ac78fbc45ac63"}}}}