Skip to content

Commit 218c8cd

Browse files
committed
Revert "fix: support multiple createRecord calls (fixes #239)"
This reverts commit d7bfcc2. (Just to show that the test indeed fails without it)
1 parent d7bfcc2 commit 218c8cd

File tree

3 files changed

+19
-50
lines changed

3 files changed

+19
-50
lines changed

addon/adapters/pouch.js

Lines changed: 17 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import Ember from 'ember';
22
import DS from 'ember-data';
33
import { pluralize } from 'ember-inflector';
4-
import { v4 } from 'uuid';
54
//import BelongsToRelationship from 'ember-data/-private/system/relationships/state/belongs-to';
65

76
import {
@@ -154,7 +153,7 @@ export default DS.RESTAdapter.extend({
154153
willDestroy: function() {
155154
this._stopChangesListener();
156155
},
157-
156+
158157
_indexPromises: [],
159158

160159
_init: function (store, type) {
@@ -207,9 +206,8 @@ export default DS.RESTAdapter.extend({
207206
relModel = (typeof rel.type === 'string' ? store.modelFor(rel.type) : rel.type);
208207
if (relModel) {
209208
let includeRel = true;
210-
if (!('options' in rel)) {
211-
rel.options = {};
212-
}
209+
if (!('options' in rel)) rel.options = {};
210+
213211
if (typeof(rel.options.async) === "undefined") {
214212
rel.options.async = config.emberPouch && !Ember.isEmpty(config.emberPouch.async) ? config.emberPouch.async : true;//default true from https://github.com/emberjs/data/pull/3366
215213
}
@@ -466,46 +464,27 @@ export default DS.RESTAdapter.extend({
466464
});
467465
},
468466

469-
generateIdForRecord: function(/* store, type, inputProperties */) {
470-
return v4();
471-
},
472-
473467
createdRecords: {},
474-
createRecord: function(store, type, snapshot) {
475-
const record = snapshot.record;
476-
if (record._emberPouchSavePromise) {
477-
const changes = record.changedAttributes();
478-
record._emberPouchSavePromise = record._emberPouchSavePromise.then(records => {
479-
// If there have been changes since the document was created then we should update the record now
480-
if (Object.keys(changes).length > 0) {
481-
const rev = records[Object.keys(records)[0]][0].rev;
482-
(snapshot.__attributes || snapshot._attributes).rev = rev; // FIXME: it should be possible to do this elsewhere
483-
return this.updateRecord(store, type, snapshot);
484-
}
485-
return records;
486-
});
487-
return record._emberPouchSavePromise;
488-
}
489-
468+
createRecord: function(store, type, record) {
490469
this._init(store, type);
491-
var data = this._recordToData(store, type, snapshot);
492-
const rel = this.get('db').rel;
493-
const id = data.id;
470+
var data = this._recordToData(store, type, record);
471+
let rel = this.get('db').rel;
472+
473+
let id = data.id;
474+
if (!id) {
475+
id = data.id = rel.uuid();
476+
}
494477
this.createdRecords[id] = true;
495-
Object.defineProperty(record, '_emberPouchSavePromise', {
496-
enumerable: false,
497-
writable: true,
498-
value: rel.save(this.getRecordTypeName(type), data).catch((e) => {
499-
delete this.createdRecords[id];
500-
throw e;
501-
}),
478+
479+
return rel.save(this.getRecordTypeName(type), data).catch((e) => {
480+
delete this.createdRecords[id];
481+
throw e;
502482
});
503-
return record._emberPouchSavePromise;
504483
},
505484

506-
updateRecord: function (store, type, snapshot) {
485+
updateRecord: function (store, type, record) {
507486
this._init(store, type);
508-
var data = this._recordToData(store, type, snapshot);
487+
var data = this._recordToData(store, type, record);
509488
return this.get('db').rel.save(this.getRecordTypeName(type), data);
510489
},
511490

ember-cli-build.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,7 @@ const EmberAddon = require('ember-cli/lib/broccoli/ember-addon');
55

66
module.exports = function(defaults) {
77
let app = new EmberAddon(defaults, {
8-
autoImport: {
9-
webpack: {
10-
node: {
11-
global: true
12-
}
13-
},
14-
// We could use ember-auto-import for these, but index.js is already handling them
15-
exclude: ['pouchdb', 'pouchdb-find', 'relational-pouch']
16-
}
8+
// Add options here
179
});
1810

1911
/*

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,9 @@
6262
"dependencies": {
6363
"broccoli-file-creator": "^2.1.1",
6464
"broccoli-stew": "^2.1.0",
65-
"ember-auto-import": "^1.5.3",
66-
"ember-cli-babel": "^7.7.3",
6765
"pouchdb": "^7.1.1",
6866
"relational-pouch": "^3.1.0",
69-
"uuid": "^3.3.3"
67+
"ember-cli-babel": "^7.7.3"
7068
},
7169
"ember-addon": {
7270
"configPath": "tests/dummy/config"

0 commit comments

Comments
 (0)