Skip to content

Commit

Permalink
Revert "fix: support multiple createRecord calls (fixes #239)"
Browse files Browse the repository at this point in the history
This reverts commit d7bfcc2.

(Just to show that the test indeed fails without it)
  • Loading branch information
jacobq committed Nov 12, 2019
1 parent d7bfcc2 commit 218c8cd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 50 deletions.
55 changes: 17 additions & 38 deletions addon/adapters/pouch.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Ember from 'ember';
import DS from 'ember-data';
import { pluralize } from 'ember-inflector';
import { v4 } from 'uuid';
//import BelongsToRelationship from 'ember-data/-private/system/relationships/state/belongs-to';

import {
Expand Down Expand Up @@ -154,7 +153,7 @@ export default DS.RESTAdapter.extend({
willDestroy: function() {
this._stopChangesListener();
},

_indexPromises: [],

_init: function (store, type) {
Expand Down Expand Up @@ -207,9 +206,8 @@ export default DS.RESTAdapter.extend({
relModel = (typeof rel.type === 'string' ? store.modelFor(rel.type) : rel.type);
if (relModel) {
let includeRel = true;
if (!('options' in rel)) {
rel.options = {};
}
if (!('options' in rel)) rel.options = {};

if (typeof(rel.options.async) === "undefined") {
rel.options.async = config.emberPouch && !Ember.isEmpty(config.emberPouch.async) ? config.emberPouch.async : true;//default true from https://github.com/emberjs/data/pull/3366
}
Expand Down Expand Up @@ -466,46 +464,27 @@ export default DS.RESTAdapter.extend({
});
},

generateIdForRecord: function(/* store, type, inputProperties */) {
return v4();
},

createdRecords: {},
createRecord: function(store, type, snapshot) {
const record = snapshot.record;
if (record._emberPouchSavePromise) {
const changes = record.changedAttributes();
record._emberPouchSavePromise = record._emberPouchSavePromise.then(records => {
// If there have been changes since the document was created then we should update the record now
if (Object.keys(changes).length > 0) {
const rev = records[Object.keys(records)[0]][0].rev;
(snapshot.__attributes || snapshot._attributes).rev = rev; // FIXME: it should be possible to do this elsewhere
return this.updateRecord(store, type, snapshot);
}
return records;
});
return record._emberPouchSavePromise;
}

createRecord: function(store, type, record) {
this._init(store, type);
var data = this._recordToData(store, type, snapshot);
const rel = this.get('db').rel;
const id = data.id;
var data = this._recordToData(store, type, record);
let rel = this.get('db').rel;

let id = data.id;
if (!id) {
id = data.id = rel.uuid();
}
this.createdRecords[id] = true;
Object.defineProperty(record, '_emberPouchSavePromise', {
enumerable: false,
writable: true,
value: rel.save(this.getRecordTypeName(type), data).catch((e) => {
delete this.createdRecords[id];
throw e;
}),

return rel.save(this.getRecordTypeName(type), data).catch((e) => {
delete this.createdRecords[id];
throw e;
});
return record._emberPouchSavePromise;
},

updateRecord: function (store, type, snapshot) {
updateRecord: function (store, type, record) {
this._init(store, type);
var data = this._recordToData(store, type, snapshot);
var data = this._recordToData(store, type, record);
return this.get('db').rel.save(this.getRecordTypeName(type), data);
},

Expand Down
10 changes: 1 addition & 9 deletions ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,7 @@ const EmberAddon = require('ember-cli/lib/broccoli/ember-addon');

module.exports = function(defaults) {
let app = new EmberAddon(defaults, {
autoImport: {
webpack: {
node: {
global: true
}
},
// We could use ember-auto-import for these, but index.js is already handling them
exclude: ['pouchdb', 'pouchdb-find', 'relational-pouch']
}
// Add options here
});

/*
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,9 @@
"dependencies": {
"broccoli-file-creator": "^2.1.1",
"broccoli-stew": "^2.1.0",
"ember-auto-import": "^1.5.3",
"ember-cli-babel": "^7.7.3",
"pouchdb": "^7.1.1",
"relational-pouch": "^3.1.0",
"uuid": "^3.3.3"
"ember-cli-babel": "^7.7.3"
},
"ember-addon": {
"configPath": "tests/dummy/config"
Expand Down

0 comments on commit 218c8cd

Please sign in to comment.