{"action":"created","comment":{"url":"https://api.github.com/repos/orbitjs/ember-orbit/pulls/comments/48636190","id":48636190,"diff_hunk":"@@ -1,379 +1,145 @@\n-import Source from './source';\n-import RecordArrayManager from './record-array-manager';\n-import OCMemorySource from 'orbit-common/memory-source';\n+import Schema from 'ember-orbit/schema';\n+import Cache from 'ember-orbit/cache';\n+import IdentityMap from 'ember-orbit/identity-map';\n+import { operationType } from 'orbit-common/lib/operations';\n \n /**\n  @module ember-orbit\n  */\n \n-var get = Ember.get;\n+const get = Ember.get;\n \n-var RSVP = Ember.RSVP;\n-\n-var PromiseArray = Ember.ArrayProxy.extend(Ember.PromiseProxyMixin);\n-function promiseArray(promise, label) {\n-  return PromiseArray.create({\n-    promise: RSVP.Promise.cast(promise, label)\n-  });\n-}\n-\n-var Store = Source.extend({\n-  orbitSourceClass: OCMemorySource,\n+var Store = Ember.Object.extend({\n+  orbitStore: Ember.inject.service('orbitStore'),\n   schema: null,\n+  cache: null,\n \n   init: function() {\n     this._super.apply(this, arguments);\n \n-    this.typeMaps = {};\n+    const { orbitStore, container } = this.getProperties('orbitStore', 'container');\n \n-    this.orbitSource.on('didTransform', this._didTransform, this);\n+    Ember.assert(get(this, 'orbitStore'), 'orbitStore is required');\n \n     this._requests = Ember.OrderedSet.create();\n \n-    this._recordArrayManager = RecordArrayManager.create({\n-      store: this\n-    });\n-  },\n-\n-  then: function(success, failure) {\n-    return this.settleRequests().then(success, failure);\n-  },\n-\n-  settleRequests: function() {\n-    return Ember.RSVP.all(this._requests.toArray());\n-  },\n-\n-  settleTransforms: function() {\n-    return this.orbitSource.settleTransforms();\n-  },\n-\n-  willDestroy: function() {\n-    this.orbitSource.off('didTransform', this.didTransform, this);\n-    this._recordArrayManager.destroy();\n-    this._super.apply(this, arguments);\n-  },\n-\n-  typeMapFor: function(type) {\n-    var typeMap = this.typeMaps[type];\n-\n-    if (typeMap) return typeMap;\n-\n-    typeMap = {\n-      records: {},\n-      type: type\n-    };\n-\n-    this.typeMaps[type] = typeMap;\n-\n-    return typeMap;\n-  },\n-\n-  transform: function(operation) {\n-    return this.orbitSource.transform(operation);\n-  },\n-\n-  all: function(type) {\n-    this._verifyType(type);\n-\n-    var typeMap = this.typeMapFor(type),\n-        findAllCache = typeMap.findAllCache;\n-\n-    if (findAllCache) { return findAllCache; }\n-\n-    var array = this._recordArrayManager.createRecordArray(type);\n-\n-    typeMap.findAllCache = array;\n-    return array;\n-  },\n-\n-  filter: function(type, query, filter) {\n-    this._verifyType(type);\n-\n-    var length = arguments.length;\n-    var hasQuery = length === 3;\n-    var promise;\n-    var array;\n-\n-    if (hasQuery) {\n-      promise = this.query(type, query);\n-    } else if (length === 2) {\n-      filter = query;\n-    }\n-\n-    if (hasQuery) {\n-      array = this._recordArrayManager.createFilteredRecordArray(type, filter, query);\n-    } else {\n-      array = this._recordArrayManager.createFilteredRecordArray(type, filter);\n-    }\n-\n-    promise = promise || RSVP.Promise.cast(array);\n-\n-    return promiseArray(promise.then(function() {\n-      return array;\n-    }, null, \"OE: Store#filter of \" + type));\n-  },\n-\n-  find: function(type, id, options) {\n-    var _this = this;\n-    this._verifyType(type);\n-\n-    var promise = this.orbitSource.find(type, id, options).then(function(data) {\n-      return _this._lookupFromData(type, data);\n-    });\n-\n-    return this._request(promise);\n-  },\n-\n-  query: function(type, query, options) {\n-    var _this = this;\n-    this._verifyType(type);\n-\n-    var promise = this.orbitSource.query(type, query, options).then(function(data) {\n-      return _this._lookupFromData(type, data);\n-    });\n-\n-    return this._request(promise);\n-  },\n-\n-  add: function(type, properties) {\n-    var _this = this;\n-    this._verifyType(type);\n-    properties = properties || {};\n-\n-    get(this, 'schema').normalize(type, properties);\n-    var promise = this.orbitSource.add(type, properties).then(function(data) {\n-      return _this._lookupFromData(type, data);\n-    });\n-\n-    return this._request(promise);\n-  },\n+    const orbitCache = orbitStore.cache;\n \n-  remove: function(type, id) {\n-    this._verifyType(type);\n-    id = this._normalizeId(id);\n+    const schema = Schema.create({ container, _orbitSchema: orbitStore.schema });\n+    this._identityMap = IdentityMap.create({ _schema: schema, _orbitCache: orbitCache, _store: this });\n+    const cache = Cache.create({ _orbitCache: orbitCache, _identityMap: this._identityMap });\n \n-    var promise = this.orbitSource.remove(type, id);\n+    this.setProperties({ schema, cache });\n \n-    return this._request(promise);\n+    orbitCache.on('patch', this._didPatch, this);\n   },\n \n-  patch: function(type, id, field, value) {\n-    this._verifyType(type);\n-    id = this._normalizeId(id);\n+  // then: function(success, failure) {\n+  //   return this.settleRequests().then(success, failure);\n+  // },\n \n-    var promise = this.orbitSource.patch(type, id, field, value);\n+  // settleRequests: function() {\n+  //   return Ember.RSVP.all(this._requests.toArray());\n+  // },\n \n-    return this._request(promise);\n+  settleTransforms: function() {","path":"lib/ember-orbit/store.js","position":189,"original_position":189,"commit_id":"8d37bfaaf7e77400bb37da70d1e37afc3306486e","original_commit_id":"8d37bfaaf7e77400bb37da70d1e37afc3306486e","user":{"login":"opsb","id":46232,"avatar_url":"https://avatars.githubusercontent.com/u/46232?v=3","gravatar_id":"","url":"https://api.github.com/users/opsb","html_url":"https://github.com/opsb","followers_url":"https://api.github.com/users/opsb/followers","following_url":"https://api.github.com/users/opsb/following{/other_user}","gists_url":"https://api.github.com/users/opsb/gists{/gist_id}","starred_url":"https://api.github.com/users/opsb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/opsb/subscriptions","organizations_url":"https://api.github.com/users/opsb/orgs","repos_url":"https://api.github.com/users/opsb/repos","events_url":"https://api.github.com/users/opsb/events{/privacy}","received_events_url":"https://api.github.com/users/opsb/received_events","type":"User","site_admin":false},"body":"it would perhaps make sense for this to be the replacement for `store.then()`","created_at":"2015-12-30T22:27:06Z","updated_at":"2015-12-30T22:27:06Z","html_url":"https://github.com/orbitjs/ember-orbit/pull/85#discussion_r48636190","pull_request_url":"https://api.github.com/repos/orbitjs/ember-orbit/pulls/85","_links":{"self":{"href":"https://api.github.com/repos/orbitjs/ember-orbit/pulls/comments/48636190"},"html":{"href":"https://github.com/orbitjs/ember-orbit/pull/85#discussion_r48636190"},"pull_request":{"href":"https://api.github.com/repos/orbitjs/ember-orbit/pulls/85"}}},"pull_request":{"url":"https://api.github.com/repos/orbitjs/ember-orbit/pulls/85","id":54833730,"html_url":"https://github.com/orbitjs/ember-orbit/pull/85","diff_url":"https://github.com/orbitjs/ember-orbit/pull/85.diff","patch_url":"https://github.com/orbitjs/ember-orbit/pull/85.patch","issue_url":"https://api.github.com/repos/orbitjs/ember-orbit/issues/85","number":85,"state":"open","locked":false,"title":"Rethink integration","user":{"login":"opsb","id":46232,"avatar_url":"https://avatars.githubusercontent.com/u/46232?v=3","gravatar_id":"","url":"https://api.github.com/users/opsb","html_url":"https://github.com/opsb","followers_url":"https://api.github.com/users/opsb/followers","following_url":"https://api.github.com/users/opsb/following{/other_user}","gists_url":"https://api.github.com/users/opsb/gists{/gist_id}","starred_url":"https://api.github.com/users/opsb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/opsb/subscriptions","organizations_url":"https://api.github.com/users/opsb/orgs","repos_url":"https://api.github.com/users/opsb/repos","events_url":"https://api.github.com/users/opsb/events{/privacy}","received_events_url":"https://api.github.com/users/opsb/received_events","type":"User","site_admin":false},"body":"@dgeb I've been working away on the initial integration and it's now fairly close to being green. I've been focused on getting to green so there's a few areas where I'm undecided about the implementation but they should be easy to refactor once we get to green. I'll try to capture all my thoughts in the line comments.\r\n\r\nI'm probably not going to get any more done it now until I get back from holidays so I thought it would be good to get this merged into a branch that you can pick up if you have time.\r\n\r\nOutstanding (there's undoubtedly more though):\r\n- [ ] store.query\r\n- [ ] secondary keys\r\n- [ ] Transaction  \r\n- [ ] relationships/has-many.js - need to implement missing methods from MutableArray\r\n- [ ] tests for schema.normalize(recordProperties) - for converting from flattened structure to orbit's json structure.","created_at":"2015-12-30T22:11:42Z","updated_at":"2015-12-30T22:27:07Z","closed_at":null,"merged_at":null,"merge_commit_sha":"14b37eda84a0c7b79b2d706242c60adc62878121","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/orbitjs/ember-orbit/pulls/85/commits","review_comments_url":"https://api.github.com/repos/orbitjs/ember-orbit/pulls/85/comments","review_comment_url":"https://api.github.com/repos/orbitjs/ember-orbit/pulls/comments{/number}","comments_url":"https://api.github.com/repos/orbitjs/ember-orbit/issues/85/comments","statuses_url":"https://api.github.com/repos/orbitjs/ember-orbit/statuses/8d37bfaaf7e77400bb37da70d1e37afc3306486e","head":{"label":"opsb:rethink_integration","ref":"rethink_integration","sha":"8d37bfaaf7e77400bb37da70d1e37afc3306486e","user":{"login":"opsb","id":46232,"avatar_url":"https://avatars.githubusercontent.com/u/46232?v=3","gravatar_id":"","url":"https://api.github.com/users/opsb","html_url":"https://github.com/opsb","followers_url":"https://api.github.com/users/opsb/followers","following_url":"https://api.github.com/users/opsb/following{/other_user}","gists_url":"https://api.github.com/users/opsb/gists{/gist_id}","starred_url":"https://api.github.com/users/opsb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/opsb/subscriptions","organizations_url":"https://api.github.com/users/opsb/orgs","repos_url":"https://api.github.com/users/opsb/repos","events_url":"https://api.github.com/users/opsb/events{/privacy}","received_events_url":"https://api.github.com/users/opsb/received_events","type":"User","site_admin":false},"repo":{"id":21045146,"name":"ember-orbit","full_name":"opsb/ember-orbit","owner":{"login":"opsb","id":46232,"avatar_url":"https://avatars.githubusercontent.com/u/46232?v=3","gravatar_id":"","url":"https://api.github.com/users/opsb","html_url":"https://github.com/opsb","followers_url":"https://api.github.com/users/opsb/followers","following_url":"https://api.github.com/users/opsb/following{/other_user}","gists_url":"https://api.github.com/users/opsb/gists{/gist_id}","starred_url":"https://api.github.com/users/opsb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/opsb/subscriptions","organizations_url":"https://api.github.com/users/opsb/orgs","repos_url":"https://api.github.com/users/opsb/repos","events_url":"https://api.github.com/users/opsb/events{/privacy}","received_events_url":"https://api.github.com/users/opsb/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/opsb/ember-orbit","description":"Ember.js data layer built with Orbit.js","fork":true,"url":"https://api.github.com/repos/opsb/ember-orbit","forks_url":"https://api.github.com/repos/opsb/ember-orbit/forks","keys_url":"https://api.github.com/repos/opsb/ember-orbit/keys{/key_id}","collaborators_url":"https://api.github.com/repos/opsb/ember-orbit/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/opsb/ember-orbit/teams","hooks_url":"https://api.github.com/repos/opsb/ember-orbit/hooks","issue_events_url":"https://api.github.com/repos/opsb/ember-orbit/issues/events{/number}","events_url":"https://api.github.com/repos/opsb/ember-orbit/events","assignees_url":"https://api.github.com/repos/opsb/ember-orbit/assignees{/user}","branches_url":"https://api.github.com/repos/opsb/ember-orbit/branches{/branch}","tags_url":"https://api.github.com/repos/opsb/ember-orbit/tags","blobs_url":"https://api.github.com/repos/opsb/ember-orbit/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/opsb/ember-orbit/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/opsb/ember-orbit/git/refs{/sha}","trees_url":"https://api.github.com/repos/opsb/ember-orbit/git/trees{/sha}","statuses_url":"https://api.github.com/repos/opsb/ember-orbit/statuses/{sha}","languages_url":"https://api.github.com/repos/opsb/ember-orbit/languages","stargazers_url":"https://api.github.com/repos/opsb/ember-orbit/stargazers","contributors_url":"https://api.github.com/repos/opsb/ember-orbit/contributors","subscribers_url":"https://api.github.com/repos/opsb/ember-orbit/subscribers","subscription_url":"https://api.github.com/repos/opsb/ember-orbit/subscription","commits_url":"https://api.github.com/repos/opsb/ember-orbit/commits{/sha}","git_commits_url":"https://api.github.com/repos/opsb/ember-orbit/git/commits{/sha}","comments_url":"https://api.github.com/repos/opsb/ember-orbit/comments{/number}","issue_comment_url":"https://api.github.com/repos/opsb/ember-orbit/issues/comments{/number}","contents_url":"https://api.github.com/repos/opsb/ember-orbit/contents/{+path}","compare_url":"https://api.github.com/repos/opsb/ember-orbit/compare/{base}...{head}","merges_url":"https://api.github.com/repos/opsb/ember-orbit/merges","archive_url":"https://api.github.com/repos/opsb/ember-orbit/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/opsb/ember-orbit/downloads","issues_url":"https://api.github.com/repos/opsb/ember-orbit/issues{/number}","pulls_url":"https://api.github.com/repos/opsb/ember-orbit/pulls{/number}","milestones_url":"https://api.github.com/repos/opsb/ember-orbit/milestones{/number}","notifications_url":"https://api.github.com/repos/opsb/ember-orbit/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/opsb/ember-orbit/labels{/name}","releases_url":"https://api.github.com/repos/opsb/ember-orbit/releases{/id}","created_at":"2014-06-20T16:47:49Z","updated_at":"2015-03-06T02:03:26Z","pushed_at":"2015-12-30T22:19:46Z","git_url":"git://github.com/opsb/ember-orbit.git","ssh_url":"git@github.com:opsb/ember-orbit.git","clone_url":"https://github.com/opsb/ember-orbit.git","svn_url":"https://github.com/opsb/ember-orbit","homepage":null,"size":313,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"orbitjs:rethink_integration","ref":"rethink_integration","sha":"e12fc7b784354651008de5363992d8c164a19739","user":{"login":"orbitjs","id":6467259,"avatar_url":"https://avatars.githubusercontent.com/u/6467259?v=3","gravatar_id":"","url":"https://api.github.com/users/orbitjs","html_url":"https://github.com/orbitjs","followers_url":"https://api.github.com/users/orbitjs/followers","following_url":"https://api.github.com/users/orbitjs/following{/other_user}","gists_url":"https://api.github.com/users/orbitjs/gists{/gist_id}","starred_url":"https://api.github.com/users/orbitjs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/orbitjs/subscriptions","organizations_url":"https://api.github.com/users/orbitjs/orgs","repos_url":"https://api.github.com/users/orbitjs/repos","events_url":"https://api.github.com/users/orbitjs/events{/privacy}","received_events_url":"https://api.github.com/users/orbitjs/received_events","type":"Organization","site_admin":false},"repo":{"id":16807601,"name":"ember-orbit","full_name":"orbitjs/ember-orbit","owner":{"login":"orbitjs","id":6467259,"avatar_url":"https://avatars.githubusercontent.com/u/6467259?v=3","gravatar_id":"","url":"https://api.github.com/users/orbitjs","html_url":"https://github.com/orbitjs","followers_url":"https://api.github.com/users/orbitjs/followers","following_url":"https://api.github.com/users/orbitjs/following{/other_user}","gists_url":"https://api.github.com/users/orbitjs/gists{/gist_id}","starred_url":"https://api.github.com/users/orbitjs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/orbitjs/subscriptions","organizations_url":"https://api.github.com/users/orbitjs/orgs","repos_url":"https://api.github.com/users/orbitjs/repos","events_url":"https://api.github.com/users/orbitjs/events{/privacy}","received_events_url":"https://api.github.com/users/orbitjs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/orbitjs/ember-orbit","description":"Ember.js data layer built with Orbit.js","fork":false,"url":"https://api.github.com/repos/orbitjs/ember-orbit","forks_url":"https://api.github.com/repos/orbitjs/ember-orbit/forks","keys_url":"https://api.github.com/repos/orbitjs/ember-orbit/keys{/key_id}","collaborators_url":"https://api.github.com/repos/orbitjs/ember-orbit/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/orbitjs/ember-orbit/teams","hooks_url":"https://api.github.com/repos/orbitjs/ember-orbit/hooks","issue_events_url":"https://api.github.com/repos/orbitjs/ember-orbit/issues/events{/number}","events_url":"https://api.github.com/repos/orbitjs/ember-orbit/events","assignees_url":"https://api.github.com/repos/orbitjs/ember-orbit/assignees{/user}","branches_url":"https://api.github.com/repos/orbitjs/ember-orbit/branches{/branch}","tags_url":"https://api.github.com/repos/orbitjs/ember-orbit/tags","blobs_url":"https://api.github.com/repos/orbitjs/ember-orbit/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/orbitjs/ember-orbit/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/orbitjs/ember-orbit/git/refs{/sha}","trees_url":"https://api.github.com/repos/orbitjs/ember-orbit/git/trees{/sha}","statuses_url":"https://api.github.com/repos/orbitjs/ember-orbit/statuses/{sha}","languages_url":"https://api.github.com/repos/orbitjs/ember-orbit/languages","stargazers_url":"https://api.github.com/repos/orbitjs/ember-orbit/stargazers","contributors_url":"https://api.github.com/repos/orbitjs/ember-orbit/contributors","subscribers_url":"https://api.github.com/repos/orbitjs/ember-orbit/subscribers","subscription_url":"https://api.github.com/repos/orbitjs/ember-orbit/subscription","commits_url":"https://api.github.com/repos/orbitjs/ember-orbit/commits{/sha}","git_commits_url":"https://api.github.com/repos/orbitjs/ember-orbit/git/commits{/sha}","comments_url":"https://api.github.com/repos/orbitjs/ember-orbit/comments{/number}","issue_comment_url":"https://api.github.com/repos/orbitjs/ember-orbit/issues/comments{/number}","contents_url":"https://api.github.com/repos/orbitjs/ember-orbit/contents/{+path}","compare_url":"https://api.github.com/repos/orbitjs/ember-orbit/compare/{base}...{head}","merges_url":"https://api.github.com/repos/orbitjs/ember-orbit/merges","archive_url":"https://api.github.com/repos/orbitjs/ember-orbit/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/orbitjs/ember-orbit/downloads","issues_url":"https://api.github.com/repos/orbitjs/ember-orbit/issues{/number}","pulls_url":"https://api.github.com/repos/orbitjs/ember-orbit/pulls{/number}","milestones_url":"https://api.github.com/repos/orbitjs/ember-orbit/milestones{/number}","notifications_url":"https://api.github.com/repos/orbitjs/ember-orbit/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/orbitjs/ember-orbit/labels{/name}","releases_url":"https://api.github.com/repos/orbitjs/ember-orbit/releases{/id}","created_at":"2014-02-13T15:42:40Z","updated_at":"2015-12-26T17:51:40Z","pushed_at":"2015-12-30T22:19:47Z","git_url":"git://github.com/orbitjs/ember-orbit.git","ssh_url":"git@github.com:orbitjs/ember-orbit.git","clone_url":"https://github.com/orbitjs/ember-orbit.git","svn_url":"https://github.com/orbitjs/ember-orbit","homepage":null,"size":347,"stargazers_count":185,"watchers_count":185,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":16,"mirror_url":null,"open_issues_count":28,"forks":16,"open_issues":28,"watchers":185,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/orbitjs/ember-orbit/pulls/85"},"html":{"href":"https://github.com/orbitjs/ember-orbit/pull/85"},"issue":{"href":"https://api.github.com/repos/orbitjs/ember-orbit/issues/85"},"comments":{"href":"https://api.github.com/repos/orbitjs/ember-orbit/issues/85/comments"},"review_comments":{"href":"https://api.github.com/repos/orbitjs/ember-orbit/pulls/85/comments"},"review_comment":{"href":"https://api.github.com/repos/orbitjs/ember-orbit/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/orbitjs/ember-orbit/pulls/85/commits"},"statuses":{"href":"https://api.github.com/repos/orbitjs/ember-orbit/statuses/8d37bfaaf7e77400bb37da70d1e37afc3306486e"}}}}