|
1 | 1 | import Ember from 'ember';
|
2 | 2 | import DS from 'ember-data';
|
3 | 3 | import { pluralize } from 'ember-inflector';
|
4 |
| -import { v4 } from 'uuid'; |
5 | 4 | //import BelongsToRelationship from 'ember-data/-private/system/relationships/state/belongs-to';
|
6 | 5 |
|
7 | 6 | import {
|
@@ -154,7 +153,7 @@ export default DS.RESTAdapter.extend({
|
154 | 153 | willDestroy: function() {
|
155 | 154 | this._stopChangesListener();
|
156 | 155 | },
|
157 |
| - |
| 156 | + |
158 | 157 | _indexPromises: [],
|
159 | 158 |
|
160 | 159 | _init: function (store, type) {
|
@@ -207,9 +206,8 @@ export default DS.RESTAdapter.extend({
|
207 | 206 | relModel = (typeof rel.type === 'string' ? store.modelFor(rel.type) : rel.type);
|
208 | 207 | if (relModel) {
|
209 | 208 | let includeRel = true;
|
210 |
| - if (!('options' in rel)) { |
211 |
| - rel.options = {}; |
212 |
| - } |
| 209 | + if (!('options' in rel)) rel.options = {}; |
| 210 | + |
213 | 211 | if (typeof(rel.options.async) === "undefined") {
|
214 | 212 | rel.options.async = config.emberPouch && !Ember.isEmpty(config.emberPouch.async) ? config.emberPouch.async : true;//default true from https://github.com/emberjs/data/pull/3366
|
215 | 213 | }
|
@@ -466,46 +464,27 @@ export default DS.RESTAdapter.extend({
|
466 | 464 | });
|
467 | 465 | },
|
468 | 466 |
|
469 |
| - generateIdForRecord: function(/* store, type, inputProperties */) { |
470 |
| - return v4(); |
471 |
| - }, |
472 |
| - |
473 | 467 | 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) { |
490 | 469 | 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 | + } |
494 | 477 | 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; |
502 | 482 | });
|
503 |
| - return record._emberPouchSavePromise; |
504 | 483 | },
|
505 | 484 |
|
506 |
| - updateRecord: function (store, type, snapshot) { |
| 485 | + updateRecord: function (store, type, record) { |
507 | 486 | this._init(store, type);
|
508 |
| - var data = this._recordToData(store, type, snapshot); |
| 487 | + var data = this._recordToData(store, type, record); |
509 | 488 | return this.get('db').rel.save(this.getRecordTypeName(type), data);
|
510 | 489 | },
|
511 | 490 |
|
|
0 commit comments