ember-data-source 3.0.0 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,7 +6,7 @@
6
6
  * @copyright Copyright 2011-2017 Tilde Inc. and contributors.
7
7
  * Portions Copyright 2011 LivingSocial Inc.
8
8
  * @license Licensed under MIT license (see license.js)
9
- * @version 3.0.0
9
+ * @version 3.0.1
10
10
  */
11
11
 
12
12
  var loader, define, requireModule, require, requirejs;
@@ -2656,12 +2656,24 @@ define('ember-data/-private/system/model/internal-model', ['exports', 'ember-dat
2656
2656
  return true;
2657
2657
  }
2658
2658
 
2659
+ // Handle dematerialization for relationship `rel`. In all cases, notify the
2660
+ // relatinoship of the dematerialization: this is done so the relationship can
2661
+ // notify its inverse which needs to update state
2662
+ //
2663
+ // If the inverse is sync, unloading this record is treated as a client-side
2664
+ // delete, so we remove the inverse records from this relationship to
2665
+ // disconnect the graph. Because it's not async, we don't need to keep around
2666
+ // the internalModel as an id-wrapper for references and because the graph is
2667
+ // disconnected we can actually destroy the internalModel when checking for
2668
+ // orphaned models.
2659
2669
  function destroyRelationship(rel) {
2660
- if (rel._inverseIsAsync()) {
2661
- rel.removeInternalModelFromInverse(rel.inverseInternalModel);
2662
- rel.removeInverseRelationships();
2663
- } else {
2664
- rel.removeCompletelyFromInverse();
2670
+ rel.internalModelDidDematerialize();
2671
+
2672
+ if (rel._inverseIsSync()) {
2673
+ // disconnect the graph so that the sync inverse relationship does not
2674
+ // prevent us from cleaning up during `_cleanupOrphanedInternalModels`
2675
+ rel.removeAllInternalModelsFromOwn();
2676
+ rel.removeAllCanonicalInternalModelsFromOwn();
2665
2677
  }
2666
2678
  }
2667
2679
  // this (and all heimdall instrumentation) will be stripped by a babel transform
@@ -2878,6 +2890,7 @@ define('ember-data/-private/system/model/internal-model', ['exports', 'ember-dat
2878
2890
 
2879
2891
  InternalModel.prototype._directlyRelatedInternalModels = function _directlyRelatedInternalModels() {
2880
2892
  var array = [];
2893
+
2881
2894
  this._relationships.forEach(function (name, rel) {
2882
2895
  array = array.concat(rel.members.list, rel.canonicalMembers.list);
2883
2896
  });
@@ -3269,10 +3282,7 @@ define('ember-data/-private/system/model/internal-model', ['exports', 'ember-dat
3269
3282
  this.__implicitRelationships = null;
3270
3283
  Object.keys(implicitRelationships).forEach(function (key) {
3271
3284
  var rel = implicitRelationships[key];
3272
-
3273
3285
  destroyRelationship(rel);
3274
-
3275
- rel.destroy();
3276
3286
  });
3277
3287
  };
3278
3288
 
@@ -8478,6 +8488,7 @@ define('ember-data/-private/system/relationships/state/belongs-to', ['exports',
8478
8488
  };
8479
8489
 
8480
8490
  BelongsToRelationship.prototype.inverseDidDematerialize = function inverseDidDematerialize() {
8491
+ _Relationship.prototype.inverseDidDematerialize.call(this, this.inverseInternalModel);
8481
8492
  this.notifyBelongsToChanged();
8482
8493
  };
8483
8494
 
@@ -8494,6 +8505,12 @@ define('ember-data/-private/system/relationships/state/belongs-to', ['exports',
8494
8505
  }
8495
8506
  };
8496
8507
 
8508
+ BelongsToRelationship.prototype.removeCompletelyFromInverse = function removeCompletelyFromInverse() {
8509
+ _Relationship.prototype.removeCompletelyFromInverse.call(this);
8510
+
8511
+ this.inverseInternalModel = null;
8512
+ };
8513
+
8497
8514
  BelongsToRelationship.prototype.flushCanonical = function flushCanonical() {
8498
8515
  //temporary fix to not remove newly created records if server returned null.
8499
8516
  //TODO remove once we have proper diffing
@@ -8538,6 +8555,12 @@ define('ember-data/-private/system/relationships/state/belongs-to', ['exports',
8538
8555
  this.notifyBelongsToChanged();
8539
8556
  };
8540
8557
 
8558
+ BelongsToRelationship.prototype.removeAllInternalModelsFromOwn = function removeAllInternalModelsFromOwn() {
8559
+ _Relationship.prototype.removeAllInternalModelsFromOwn.call(this);
8560
+ this.inverseInternalModel = null;
8561
+ this.notifyBelongsToChanged();
8562
+ };
8563
+
8541
8564
  BelongsToRelationship.prototype.notifyBelongsToChanged = function notifyBelongsToChanged() {
8542
8565
  this.internalModel.notifyBelongsToChanged(this.key);
8543
8566
  };
@@ -8550,6 +8573,11 @@ define('ember-data/-private/system/relationships/state/belongs-to', ['exports',
8550
8573
  _Relationship.prototype.removeCanonicalInternalModelFromOwn.call(this, internalModel);
8551
8574
  };
8552
8575
 
8576
+ BelongsToRelationship.prototype.removeAllCanonicalInternalModelsFromOwn = function removeAllCanonicalInternalModelsFromOwn() {
8577
+ _Relationship.prototype.removeAllCanonicalInternalModelsFromOwn.call(this);
8578
+ this.canonicalState = null;
8579
+ };
8580
+
8553
8581
  BelongsToRelationship.prototype.findRecord = function findRecord() {
8554
8582
  if (this.inverseInternalModel) {
8555
8583
  return this.store._findByInternalModel(this.inverseInternalModel);
@@ -8810,7 +8838,12 @@ define('ember-data/-private/system/relationships/state/has-many', ['exports', 'e
8810
8838
  _this.belongsToType = relationshipMeta.type;
8811
8839
  _this.canonicalState = [];
8812
8840
  _this.isPolymorphic = relationshipMeta.options.polymorphic;
8841
+ // The ManyArray for this relationship
8813
8842
  _this._manyArray = null;
8843
+ // The previous ManyArray for this relationship. It will be destroyed when
8844
+ // we create a new many array, but in the interim it will be updated if
8845
+ // inverse internal models are unloaded.
8846
+ _this._retainedManyArray = null;
8814
8847
  _this.__loadingPromise = null;
8815
8848
  return _this;
8816
8849
  }
@@ -8862,10 +8895,14 @@ define('ember-data/-private/system/relationships/state/has-many', ['exports', 'e
8862
8895
  _Relationship.prototype.addCanonicalInternalModel.call(this, internalModel, idx);
8863
8896
  };
8864
8897
 
8865
- ManyRelationship.prototype.inverseDidDematerialize = function inverseDidDematerialize() {
8866
- if (this._manyArray) {
8867
- this._manyArray.destroy();
8868
- this._manyArray = null;
8898
+ ManyRelationship.prototype.inverseDidDematerialize = function inverseDidDematerialize(inverseInternalModel) {
8899
+ _Relationship.prototype.inverseDidDematerialize.call(this, inverseInternalModel);
8900
+ if (this.isAsync) {
8901
+ if (this._manyArray) {
8902
+ this._retainedManyArray = this._manyArray;
8903
+ this._manyArray = null;
8904
+ }
8905
+ this._removeInternalModelFromManyArray(this._retainedManyArray, inverseInternalModel);
8869
8906
  }
8870
8907
  this.notifyHasManyChanged();
8871
8908
  };
@@ -8894,6 +8931,12 @@ define('ember-data/-private/system/relationships/state/has-many', ['exports', 'e
8894
8931
  _Relationship.prototype.removeCanonicalInternalModelFromOwn.call(this, internalModel, idx);
8895
8932
  };
8896
8933
 
8934
+ ManyRelationship.prototype.removeAllCanonicalInternalModelsFromOwn = function removeAllCanonicalInternalModelsFromOwn() {
8935
+ _Relationship.prototype.removeAllCanonicalInternalModelsFromOwn.call(this);
8936
+ this.canonicalMembers.clear();
8937
+ this.canonicalState.splice(0, this.canonicalState.length);
8938
+ };
8939
+
8897
8940
  ManyRelationship.prototype.removeCompletelyFromOwn = function removeCompletelyFromOwn(internalModel) {
8898
8941
  _Relationship.prototype.removeCompletelyFromOwn.call(this, internalModel);
8899
8942
 
@@ -8926,7 +8969,33 @@ define('ember-data/-private/system/relationships/state/has-many', ['exports', 'e
8926
8969
  return;
8927
8970
  }
8928
8971
  _Relationship.prototype.removeInternalModelFromOwn.call(this, internalModel, idx);
8929
- var manyArray = this.manyArray;
8972
+ // note that ensuring the many array is created, via `this.manyArray`
8973
+ // (instead of `this._manyArray`) is intentional.
8974
+ //
8975
+ // Because we're removing from local, and not canonical, state, it is
8976
+ // important that the many array is initialized now with those changes,
8977
+ // otherwise it will be initialized with canonical state and we'll have
8978
+ // lost the fact that this internalModel was removed.
8979
+ this._removeInternalModelFromManyArray(this.manyArray, internalModel, idx);
8980
+ this._removeInternalModelFromManyArray(this._retainedManyArray, internalModel, idx);
8981
+ };
8982
+
8983
+ ManyRelationship.prototype.removeAllInternalModelsFromOwn = function removeAllInternalModelsFromOwn() {
8984
+ _Relationship.prototype.removeAllInternalModelsFromOwn.call(this);
8985
+ // as with removeInternalModelFromOwn, we make sure the many array is
8986
+ // instantiated, or we'll lose local removals, as we're not updating
8987
+ // canonical state here.
8988
+ this.manyArray.clear();
8989
+ if (this._retainedManyArray) {
8990
+ this._retainedManyArray.clear();
8991
+ }
8992
+ };
8993
+
8994
+ ManyRelationship.prototype._removeInternalModelFromManyArray = function _removeInternalModelFromManyArray(manyArray, internalModel, idx) {
8995
+ if (manyArray === null) {
8996
+ return;
8997
+ }
8998
+
8930
8999
  if (idx !== undefined) {
8931
9000
  //TODO(Igor) not used currently, fix
8932
9001
  manyArray.currentState.removeAt(idx);
@@ -9088,12 +9157,14 @@ define('ember-data/-private/system/relationships/state/has-many', ['exports', 'e
9088
9157
  var manyArray = this._manyArray;
9089
9158
  if (manyArray) {
9090
9159
  manyArray.destroy();
9160
+ this._manyArray = null;
9091
9161
  }
9092
9162
 
9093
9163
  var proxy = this.__loadingPromise;
9094
9164
 
9095
9165
  if (proxy) {
9096
9166
  proxy.destroy();
9167
+ this.__loadingPromise = null;
9097
9168
  }
9098
9169
  };
9099
9170
 
@@ -9105,6 +9176,9 @@ define('ember-data/-private/system/relationships/state/has-many', ['exports', 'e
9105
9176
  }, {
9106
9177
  key: 'manyArray',
9107
9178
  get: function () {
9179
+ (false && Ember.assert('Error: relationship ' + this.parentType + ':' + this.key + ' has both many array and retained many array', this._manyArray === null || this._retainedManyArray === null));
9180
+
9181
+
9108
9182
  if (!this._manyArray) {
9109
9183
  this._manyArray = _manyArray.default.create({
9110
9184
  canonicalState: this.canonicalState,
@@ -9115,7 +9189,13 @@ define('ember-data/-private/system/relationships/state/has-many', ['exports', 'e
9115
9189
  meta: this.meta,
9116
9190
  isPolymorphic: this.isPolymorphic
9117
9191
  });
9192
+
9193
+ if (this._retainedManyArray !== null) {
9194
+ this._retainedManyArray.destroy();
9195
+ this._retainedManyArray = null;
9196
+ }
9118
9197
  }
9198
+
9119
9199
  return this._manyArray;
9120
9200
  }
9121
9201
  }]);
@@ -9168,6 +9248,7 @@ define('ember-data/-private/system/relationships/state/relationship', ['exports'
9168
9248
  }();
9169
9249
 
9170
9250
  var guidFor = Ember.guidFor;
9251
+ var get = Ember.get;
9171
9252
 
9172
9253
  var Relationship = function () {
9173
9254
  function Relationship(store, internalModel, inverseKey, relationshipMeta) {
@@ -9189,34 +9270,52 @@ define('ember-data/-private/system/relationships/state/relationship', ['exports'
9189
9270
  this.meta = null;
9190
9271
  this.hasData = false;
9191
9272
  this.hasLoaded = false;
9273
+ this.__inverseMeta = undefined;
9192
9274
  }
9193
9275
 
9194
9276
  Relationship.prototype._inverseIsAsync = function _inverseIsAsync() {
9195
- if (!this.inverseKey || !this.inverseInternalModel) {
9277
+ var inverseMeta = this._inverseMeta;
9278
+ if (!inverseMeta) {
9196
9279
  return false;
9197
9280
  }
9198
- return this.inverseInternalModel._relationships.get(this.inverseKey).isAsync;
9281
+
9282
+ var inverseAsync = inverseMeta.options.async;
9283
+ return typeof inverseAsync === 'undefined' ? true : inverseAsync;
9199
9284
  };
9200
9285
 
9201
- Relationship.prototype.removeInverseRelationships = function removeInverseRelationships() {
9286
+ Relationship.prototype._inverseIsSync = function _inverseIsSync() {
9287
+ var inverseMeta = this._inverseMeta;
9288
+ if (!inverseMeta) {
9289
+ return false;
9290
+ }
9291
+
9292
+ var inverseAsync = inverseMeta.options.async;
9293
+ return typeof inverseAsync === 'undefined' ? false : !inverseAsync;
9294
+ };
9295
+
9296
+ Relationship.prototype.internalModelDidDematerialize = function internalModelDidDematerialize() {
9297
+ var _this = this;
9298
+
9202
9299
  if (!this.inverseKey) {
9203
9300
  return;
9204
9301
  }
9205
9302
 
9206
- var allMembers =
9207
- // we actually want a union of members and canonicalMembers
9208
- // they should be disjoint but currently are not due to a bug
9209
- this.members.list.concat(this.canonicalMembers.list);
9303
+ this.forAllMembers(function (inverseInternalModel) {
9304
+ var relationship = inverseInternalModel._relationships.get(_this.inverseKey);
9305
+ relationship.inverseDidDematerialize(_this.internalModel);
9306
+ });
9307
+ };
9210
9308
 
9211
- for (var i = 0; i < allMembers.length; i++) {
9212
- var inverseInternalModel = allMembers[i];
9213
- var relationship = inverseInternalModel._relationships.get(this.inverseKey);
9214
- relationship.inverseDidDematerialize();
9309
+ Relationship.prototype.inverseDidDematerialize = function inverseDidDematerialize(inverseInternalModel) {
9310
+ if (!this.isAsync) {
9311
+ // unloading inverse of a sync relationship is treated as a client-side
9312
+ // delete, so actually remove the models don't merely invalidate the cp
9313
+ // cache.
9314
+ this.removeInternalModelFromOwn(inverseInternalModel);
9315
+ this.removeCanonicalInternalModelFromOwn(inverseInternalModel);
9215
9316
  }
9216
9317
  };
9217
9318
 
9218
- Relationship.prototype.inverseDidDematerialize = function inverseDidDematerialize() {};
9219
-
9220
9319
  Relationship.prototype.updateMeta = function updateMeta(meta) {
9221
9320
  this.meta = meta;
9222
9321
  };
@@ -9236,19 +9335,29 @@ define('ember-data/-private/system/relationships/state/relationship', ['exports'
9236
9335
  }
9237
9336
  };
9238
9337
 
9338
+ Relationship.prototype.removeAllInternalModelsFromOwn = function removeAllInternalModelsFromOwn() {
9339
+ this.members.clear();
9340
+ this.internalModel.updateRecordArrays();
9341
+ };
9342
+
9343
+ Relationship.prototype.removeAllCanonicalInternalModelsFromOwn = function removeAllCanonicalInternalModelsFromOwn() {
9344
+ this.canonicalMembers.clear();
9345
+ this.flushCanonicalLater();
9346
+ };
9347
+
9239
9348
  Relationship.prototype.removeInternalModels = function removeInternalModels(internalModels) {
9240
- var _this = this;
9349
+ var _this2 = this;
9241
9350
 
9242
9351
  internalModels.forEach(function (internalModel) {
9243
- return _this.removeInternalModel(internalModel);
9352
+ return _this2.removeInternalModel(internalModel);
9244
9353
  });
9245
9354
  };
9246
9355
 
9247
9356
  Relationship.prototype.addInternalModels = function addInternalModels(internalModels, idx) {
9248
- var _this2 = this;
9357
+ var _this3 = this;
9249
9358
 
9250
9359
  internalModels.forEach(function (internalModel) {
9251
- _this2.addInternalModel(internalModel, idx);
9360
+ _this3.addInternalModel(internalModel, idx);
9252
9361
  if (idx !== undefined) {
9253
9362
  idx++;
9254
9363
  }
@@ -9291,7 +9400,7 @@ define('ember-data/-private/system/relationships/state/relationship', ['exports'
9291
9400
  var _relationships = internalModel._implicitRelationships;
9292
9401
  var _relationship = _relationships[this.inverseKeyForImplicit];
9293
9402
  if (!_relationship) {
9294
- _relationship = _relationships[this.inverseKeyForImplicit] = new Relationship(this.store, internalModel, this.key, { options: { async: this.isAsync } });
9403
+ _relationship = _relationships[this.inverseKeyForImplicit] = new Relationship(this.store, internalModel, this.key, { options: { async: this.isAsync }, type: this.parentType });
9295
9404
  }
9296
9405
  _relationship.addCanonicalInternalModel(this.internalModel);
9297
9406
  }
@@ -9329,7 +9438,7 @@ define('ember-data/-private/system/relationships/state/relationship', ['exports'
9329
9438
  internalModel._relationships.get(this.inverseKey).addInternalModel(this.internalModel);
9330
9439
  } else {
9331
9440
  if (!internalModel._implicitRelationships[this.inverseKeyForImplicit]) {
9332
- internalModel._implicitRelationships[this.inverseKeyForImplicit] = new Relationship(this.store, internalModel, this.key, { options: { async: this.isAsync } });
9441
+ internalModel._implicitRelationships[this.inverseKeyForImplicit] = new Relationship(this.store, internalModel, this.key, { options: { async: this.isAsync }, type: this.parentType });
9333
9442
  }
9334
9443
  internalModel._implicitRelationships[this.inverseKeyForImplicit].addInternalModel(this.internalModel);
9335
9444
  }
@@ -9378,7 +9487,7 @@ define('ember-data/-private/system/relationships/state/relationship', ['exports'
9378
9487
  };
9379
9488
 
9380
9489
  Relationship.prototype.removeCompletelyFromInverse = function removeCompletelyFromInverse() {
9381
- var _this3 = this;
9490
+ var _this4 = this;
9382
9491
 
9383
9492
  if (!this.inverseKey) {
9384
9493
  return;
@@ -9393,7 +9502,7 @@ define('ember-data/-private/system/relationships/state/relationship', ['exports'
9393
9502
  var id = guidFor(inverseInternalModel);
9394
9503
 
9395
9504
  if (seen[id] === undefined) {
9396
- var relationship = inverseInternalModel._relationships.get(_this3.inverseKey);
9505
+ var relationship = inverseInternalModel._relationships.get(_this4.inverseKey);
9397
9506
  relationship.removeCompletelyFromOwn(internalModel);
9398
9507
  seen[id] = true;
9399
9508
  }
@@ -9401,6 +9510,32 @@ define('ember-data/-private/system/relationships/state/relationship', ['exports'
9401
9510
 
9402
9511
  this.members.forEach(unload);
9403
9512
  this.canonicalMembers.forEach(unload);
9513
+
9514
+ if (!this.isAsync) {
9515
+ this.clear();
9516
+ }
9517
+ };
9518
+
9519
+ Relationship.prototype.forAllMembers = function forAllMembers(callback) {
9520
+ var seen = Object.create(null);
9521
+
9522
+ for (var i = 0; i < this.members.list.length; i++) {
9523
+ var inverseInternalModel = this.members.list[i];
9524
+ var id = guidFor(inverseInternalModel);
9525
+ if (!seen[id]) {
9526
+ seen[id] = true;
9527
+ callback(inverseInternalModel);
9528
+ }
9529
+ }
9530
+
9531
+ for (var _i = 0; _i < this.canonicalMembers.list.length; _i++) {
9532
+ var _inverseInternalModel = this.canonicalMembers.list[_i];
9533
+ var _id = guidFor(_inverseInternalModel);
9534
+ if (!seen[_id]) {
9535
+ seen[_id] = true;
9536
+ callback(_inverseInternalModel);
9537
+ }
9538
+ }
9404
9539
  };
9405
9540
 
9406
9541
  Relationship.prototype.removeCompletelyFromOwn = function removeCompletelyFromOwn(internalModel) {
@@ -9423,8 +9558,8 @@ define('ember-data/-private/system/relationships/state/relationship', ['exports'
9423
9558
 
9424
9559
  //TODO(Igor) make this less abysmally slow
9425
9560
  this.members = this.canonicalMembers.copy();
9426
- for (var _i = 0; _i < newInternalModels.length; _i++) {
9427
- this.members.add(newInternalModels[_i]);
9561
+ for (var _i2 = 0; _i2 < newInternalModels.length; _i2++) {
9562
+ this.members.add(newInternalModels[_i2]);
9428
9563
  }
9429
9564
  };
9430
9565
 
@@ -9525,6 +9660,23 @@ define('ember-data/-private/system/relationships/state/relationship', ['exports'
9525
9660
  Relationship.prototype.destroy = function destroy() {};
9526
9661
 
9527
9662
  _createClass(Relationship, [{
9663
+ key: '_inverseMeta',
9664
+ get: function () {
9665
+ if (this.__inverseMeta === undefined) {
9666
+ var inverseMeta = null;
9667
+
9668
+ if (this.inverseKey) {
9669
+ var inverseModelClass = this.store.modelFor(this.relationshipMeta.type);
9670
+ var inverseRelationships = get(inverseModelClass, 'relationshipsByName');
9671
+ inverseMeta = inverseRelationships.get(this.inverseKey);
9672
+ }
9673
+
9674
+ this.__inverseMeta = inverseMeta;
9675
+ }
9676
+
9677
+ return this.__inverseMeta;
9678
+ }
9679
+ }, {
9528
9680
  key: 'parentType',
9529
9681
  get: function () {
9530
9682
  return this.internalModel.modelName;
@@ -17930,7 +18082,7 @@ define("ember-data/version", ["exports"], function (exports) {
17930
18082
  "use strict";
17931
18083
 
17932
18084
  exports.__esModule = true;
17933
- exports.default = "3.0.0";
18085
+ exports.default = "3.0.1";
17934
18086
  });
17935
18087
  define("ember-inflector", ["module", "exports", "ember-inflector/lib/system", "ember-inflector/lib/ext/string"], function (module, exports, _system) {
17936
18088
  "use strict";
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ember-data",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "description": "A data layer for your Ember applications.",
5
5
  "repository": "git://github.com/emberjs/data.git",
6
6
  "directories": {
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ember-data-source
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yehuda Katz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-12 00:00:00.000000000 Z
11
+ date: 2018-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ember-source