ember-data-source 2.18.0 → 2.18.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 2.18.0
9
+ * @version 2.18.1
10
10
  */
11
11
 
12
12
  var loader, define, requireModule, require, requirejs;
@@ -2689,12 +2689,24 @@ define('ember-data/-private/system/model/internal-model', ['exports', 'ember-dat
2689
2689
  return true;
2690
2690
  }
2691
2691
 
2692
+ // Handle dematerialization for relationship `rel`. In all cases, notify the
2693
+ // relatinoship of the dematerialization: this is done so the relationship can
2694
+ // notify its inverse which needs to update state
2695
+ //
2696
+ // If the inverse is sync, unloading this record is treated as a client-side
2697
+ // delete, so we remove the inverse records from this relationship to
2698
+ // disconnect the graph. Because it's not async, we don't need to keep around
2699
+ // the internalModel as an id-wrapper for references and because the graph is
2700
+ // disconnected we can actually destroy the internalModel when checking for
2701
+ // orphaned models.
2692
2702
  function destroyRelationship(rel) {
2693
- if (rel._inverseIsAsync()) {
2694
- rel.removeInternalModelFromInverse(rel.inverseInternalModel);
2695
- rel.removeInverseRelationships();
2696
- } else {
2697
- rel.removeCompletelyFromInverse();
2703
+ rel.internalModelDidDematerialize();
2704
+
2705
+ if (rel._inverseIsSync()) {
2706
+ // disconnect the graph so that the sync inverse relationship does not
2707
+ // prevent us from cleaning up during `_cleanupOrphanedInternalModels`
2708
+ rel.removeAllInternalModelsFromOwn();
2709
+ rel.removeAllCanonicalInternalModelsFromOwn();
2698
2710
  }
2699
2711
  }
2700
2712
  // this (and all heimdall instrumentation) will be stripped by a babel transform
@@ -2911,6 +2923,7 @@ define('ember-data/-private/system/model/internal-model', ['exports', 'ember-dat
2911
2923
 
2912
2924
  InternalModel.prototype._directlyRelatedInternalModels = function _directlyRelatedInternalModels() {
2913
2925
  var array = [];
2926
+
2914
2927
  this._relationships.forEach(function (name, rel) {
2915
2928
  array = array.concat(rel.members.list, rel.canonicalMembers.list);
2916
2929
  });
@@ -3308,10 +3321,7 @@ define('ember-data/-private/system/model/internal-model', ['exports', 'ember-dat
3308
3321
  this.__implicitRelationships = null;
3309
3322
  Object.keys(implicitRelationships).forEach(function (key) {
3310
3323
  var rel = implicitRelationships[key];
3311
-
3312
3324
  destroyRelationship(rel);
3313
-
3314
- rel.destroy();
3315
3325
  });
3316
3326
  };
3317
3327
 
@@ -8544,6 +8554,7 @@ define('ember-data/-private/system/relationships/state/belongs-to', ['exports',
8544
8554
  };
8545
8555
 
8546
8556
  BelongsToRelationship.prototype.inverseDidDematerialize = function inverseDidDematerialize() {
8557
+ _Relationship.prototype.inverseDidDematerialize.call(this, this.inverseInternalModel);
8547
8558
  this.notifyBelongsToChanged();
8548
8559
  };
8549
8560
 
@@ -8560,6 +8571,12 @@ define('ember-data/-private/system/relationships/state/belongs-to', ['exports',
8560
8571
  }
8561
8572
  };
8562
8573
 
8574
+ BelongsToRelationship.prototype.removeCompletelyFromInverse = function removeCompletelyFromInverse() {
8575
+ _Relationship.prototype.removeCompletelyFromInverse.call(this);
8576
+
8577
+ this.inverseInternalModel = null;
8578
+ };
8579
+
8563
8580
  BelongsToRelationship.prototype.flushCanonical = function flushCanonical() {
8564
8581
  //temporary fix to not remove newly created records if server returned null.
8565
8582
  //TODO remove once we have proper diffing
@@ -8604,6 +8621,12 @@ define('ember-data/-private/system/relationships/state/belongs-to', ['exports',
8604
8621
  this.notifyBelongsToChanged();
8605
8622
  };
8606
8623
 
8624
+ BelongsToRelationship.prototype.removeAllInternalModelsFromOwn = function removeAllInternalModelsFromOwn() {
8625
+ _Relationship.prototype.removeAllInternalModelsFromOwn.call(this);
8626
+ this.inverseInternalModel = null;
8627
+ this.notifyBelongsToChanged();
8628
+ };
8629
+
8607
8630
  BelongsToRelationship.prototype.notifyBelongsToChanged = function notifyBelongsToChanged() {
8608
8631
  this.internalModel.notifyBelongsToChanged(this.key);
8609
8632
  };
@@ -8616,6 +8639,11 @@ define('ember-data/-private/system/relationships/state/belongs-to', ['exports',
8616
8639
  _Relationship.prototype.removeCanonicalInternalModelFromOwn.call(this, internalModel);
8617
8640
  };
8618
8641
 
8642
+ BelongsToRelationship.prototype.removeAllCanonicalInternalModelsFromOwn = function removeAllCanonicalInternalModelsFromOwn() {
8643
+ _Relationship.prototype.removeAllCanonicalInternalModelsFromOwn.call(this);
8644
+ this.canonicalState = null;
8645
+ };
8646
+
8619
8647
  BelongsToRelationship.prototype.findRecord = function findRecord() {
8620
8648
  if (this.inverseInternalModel) {
8621
8649
  return this.store._findByInternalModel(this.inverseInternalModel);
@@ -8876,7 +8904,12 @@ define('ember-data/-private/system/relationships/state/has-many', ['exports', 'e
8876
8904
  _this.belongsToType = relationshipMeta.type;
8877
8905
  _this.canonicalState = [];
8878
8906
  _this.isPolymorphic = relationshipMeta.options.polymorphic;
8907
+ // The ManyArray for this relationship
8879
8908
  _this._manyArray = null;
8909
+ // The previous ManyArray for this relationship. It will be destroyed when
8910
+ // we create a new many array, but in the interim it will be updated if
8911
+ // inverse internal models are unloaded.
8912
+ _this._retainedManyArray = null;
8880
8913
  _this.__loadingPromise = null;
8881
8914
  return _this;
8882
8915
  }
@@ -8928,10 +8961,14 @@ define('ember-data/-private/system/relationships/state/has-many', ['exports', 'e
8928
8961
  _Relationship.prototype.addCanonicalInternalModel.call(this, internalModel, idx);
8929
8962
  };
8930
8963
 
8931
- ManyRelationship.prototype.inverseDidDematerialize = function inverseDidDematerialize() {
8932
- if (this._manyArray) {
8933
- this._manyArray.destroy();
8934
- this._manyArray = null;
8964
+ ManyRelationship.prototype.inverseDidDematerialize = function inverseDidDematerialize(inverseInternalModel) {
8965
+ _Relationship.prototype.inverseDidDematerialize.call(this, inverseInternalModel);
8966
+ if (this.isAsync) {
8967
+ if (this._manyArray) {
8968
+ this._retainedManyArray = this._manyArray;
8969
+ this._manyArray = null;
8970
+ }
8971
+ this._removeInternalModelFromManyArray(this._retainedManyArray, inverseInternalModel);
8935
8972
  }
8936
8973
  this.notifyHasManyChanged();
8937
8974
  };
@@ -8960,6 +8997,12 @@ define('ember-data/-private/system/relationships/state/has-many', ['exports', 'e
8960
8997
  _Relationship.prototype.removeCanonicalInternalModelFromOwn.call(this, internalModel, idx);
8961
8998
  };
8962
8999
 
9000
+ ManyRelationship.prototype.removeAllCanonicalInternalModelsFromOwn = function removeAllCanonicalInternalModelsFromOwn() {
9001
+ _Relationship.prototype.removeAllCanonicalInternalModelsFromOwn.call(this);
9002
+ this.canonicalMembers.clear();
9003
+ this.canonicalState.splice(0, this.canonicalState.length);
9004
+ };
9005
+
8963
9006
  ManyRelationship.prototype.removeCompletelyFromOwn = function removeCompletelyFromOwn(internalModel) {
8964
9007
  _Relationship.prototype.removeCompletelyFromOwn.call(this, internalModel);
8965
9008
 
@@ -8992,7 +9035,33 @@ define('ember-data/-private/system/relationships/state/has-many', ['exports', 'e
8992
9035
  return;
8993
9036
  }
8994
9037
  _Relationship.prototype.removeInternalModelFromOwn.call(this, internalModel, idx);
8995
- var manyArray = this.manyArray;
9038
+ // note that ensuring the many array is created, via `this.manyArray`
9039
+ // (instead of `this._manyArray`) is intentional.
9040
+ //
9041
+ // Because we're removing from local, and not canonical, state, it is
9042
+ // important that the many array is initialized now with those changes,
9043
+ // otherwise it will be initialized with canonical state and we'll have
9044
+ // lost the fact that this internalModel was removed.
9045
+ this._removeInternalModelFromManyArray(this.manyArray, internalModel, idx);
9046
+ this._removeInternalModelFromManyArray(this._retainedManyArray, internalModel, idx);
9047
+ };
9048
+
9049
+ ManyRelationship.prototype.removeAllInternalModelsFromOwn = function removeAllInternalModelsFromOwn() {
9050
+ _Relationship.prototype.removeAllInternalModelsFromOwn.call(this);
9051
+ // as with removeInternalModelFromOwn, we make sure the many array is
9052
+ // instantiated, or we'll lose local removals, as we're not updating
9053
+ // canonical state here.
9054
+ this.manyArray.clear();
9055
+ if (this._retainedManyArray) {
9056
+ this._retainedManyArray.clear();
9057
+ }
9058
+ };
9059
+
9060
+ ManyRelationship.prototype._removeInternalModelFromManyArray = function _removeInternalModelFromManyArray(manyArray, internalModel, idx) {
9061
+ if (manyArray === null) {
9062
+ return;
9063
+ }
9064
+
8996
9065
  if (idx !== undefined) {
8997
9066
  //TODO(Igor) not used currently, fix
8998
9067
  manyArray.currentState.removeAt(idx);
@@ -9154,12 +9223,14 @@ define('ember-data/-private/system/relationships/state/has-many', ['exports', 'e
9154
9223
  var manyArray = this._manyArray;
9155
9224
  if (manyArray) {
9156
9225
  manyArray.destroy();
9226
+ this._manyArray = null;
9157
9227
  }
9158
9228
 
9159
9229
  var proxy = this.__loadingPromise;
9160
9230
 
9161
9231
  if (proxy) {
9162
9232
  proxy.destroy();
9233
+ this.__loadingPromise = null;
9163
9234
  }
9164
9235
  };
9165
9236
 
@@ -9171,6 +9242,9 @@ define('ember-data/-private/system/relationships/state/has-many', ['exports', 'e
9171
9242
  }, {
9172
9243
  key: 'manyArray',
9173
9244
  get: function () {
9245
+ (false && Ember.assert('Error: relationship ' + this.parentType + ':' + this.key + ' has both many array and retained many array', this._manyArray === null || this._retainedManyArray === null));
9246
+
9247
+
9174
9248
  if (!this._manyArray) {
9175
9249
  this._manyArray = _manyArray.default.create({
9176
9250
  canonicalState: this.canonicalState,
@@ -9181,7 +9255,13 @@ define('ember-data/-private/system/relationships/state/has-many', ['exports', 'e
9181
9255
  meta: this.meta,
9182
9256
  isPolymorphic: this.isPolymorphic
9183
9257
  });
9258
+
9259
+ if (this._retainedManyArray !== null) {
9260
+ this._retainedManyArray.destroy();
9261
+ this._retainedManyArray = null;
9262
+ }
9184
9263
  }
9264
+
9185
9265
  return this._manyArray;
9186
9266
  }
9187
9267
  }]);
@@ -9234,6 +9314,7 @@ define('ember-data/-private/system/relationships/state/relationship', ['exports'
9234
9314
  }();
9235
9315
 
9236
9316
  var guidFor = Ember.guidFor;
9317
+ var get = Ember.get;
9237
9318
 
9238
9319
  var Relationship = function () {
9239
9320
  function Relationship(store, internalModel, inverseKey, relationshipMeta) {
@@ -9255,34 +9336,52 @@ define('ember-data/-private/system/relationships/state/relationship', ['exports'
9255
9336
  this.meta = null;
9256
9337
  this.hasData = false;
9257
9338
  this.hasLoaded = false;
9339
+ this.__inverseMeta = undefined;
9258
9340
  }
9259
9341
 
9260
9342
  Relationship.prototype._inverseIsAsync = function _inverseIsAsync() {
9261
- if (!this.inverseKey || !this.inverseInternalModel) {
9343
+ var inverseMeta = this._inverseMeta;
9344
+ if (!inverseMeta) {
9262
9345
  return false;
9263
9346
  }
9264
- return this.inverseInternalModel._relationships.get(this.inverseKey).isAsync;
9347
+
9348
+ var inverseAsync = inverseMeta.options.async;
9349
+ return typeof inverseAsync === 'undefined' ? true : inverseAsync;
9265
9350
  };
9266
9351
 
9267
- Relationship.prototype.removeInverseRelationships = function removeInverseRelationships() {
9352
+ Relationship.prototype._inverseIsSync = function _inverseIsSync() {
9353
+ var inverseMeta = this._inverseMeta;
9354
+ if (!inverseMeta) {
9355
+ return false;
9356
+ }
9357
+
9358
+ var inverseAsync = inverseMeta.options.async;
9359
+ return typeof inverseAsync === 'undefined' ? false : !inverseAsync;
9360
+ };
9361
+
9362
+ Relationship.prototype.internalModelDidDematerialize = function internalModelDidDematerialize() {
9363
+ var _this = this;
9364
+
9268
9365
  if (!this.inverseKey) {
9269
9366
  return;
9270
9367
  }
9271
9368
 
9272
- var allMembers =
9273
- // we actually want a union of members and canonicalMembers
9274
- // they should be disjoint but currently are not due to a bug
9275
- this.members.list.concat(this.canonicalMembers.list);
9369
+ this.forAllMembers(function (inverseInternalModel) {
9370
+ var relationship = inverseInternalModel._relationships.get(_this.inverseKey);
9371
+ relationship.inverseDidDematerialize(_this.internalModel);
9372
+ });
9373
+ };
9276
9374
 
9277
- for (var i = 0; i < allMembers.length; i++) {
9278
- var inverseInternalModel = allMembers[i];
9279
- var relationship = inverseInternalModel._relationships.get(this.inverseKey);
9280
- relationship.inverseDidDematerialize();
9375
+ Relationship.prototype.inverseDidDematerialize = function inverseDidDematerialize(inverseInternalModel) {
9376
+ if (!this.isAsync) {
9377
+ // unloading inverse of a sync relationship is treated as a client-side
9378
+ // delete, so actually remove the models don't merely invalidate the cp
9379
+ // cache.
9380
+ this.removeInternalModelFromOwn(inverseInternalModel);
9381
+ this.removeCanonicalInternalModelFromOwn(inverseInternalModel);
9281
9382
  }
9282
9383
  };
9283
9384
 
9284
- Relationship.prototype.inverseDidDematerialize = function inverseDidDematerialize() {};
9285
-
9286
9385
  Relationship.prototype.updateMeta = function updateMeta(meta) {
9287
9386
  this.meta = meta;
9288
9387
  };
@@ -9302,19 +9401,29 @@ define('ember-data/-private/system/relationships/state/relationship', ['exports'
9302
9401
  }
9303
9402
  };
9304
9403
 
9404
+ Relationship.prototype.removeAllInternalModelsFromOwn = function removeAllInternalModelsFromOwn() {
9405
+ this.members.clear();
9406
+ this.internalModel.updateRecordArrays();
9407
+ };
9408
+
9409
+ Relationship.prototype.removeAllCanonicalInternalModelsFromOwn = function removeAllCanonicalInternalModelsFromOwn() {
9410
+ this.canonicalMembers.clear();
9411
+ this.flushCanonicalLater();
9412
+ };
9413
+
9305
9414
  Relationship.prototype.removeInternalModels = function removeInternalModels(internalModels) {
9306
- var _this = this;
9415
+ var _this2 = this;
9307
9416
 
9308
9417
  internalModels.forEach(function (internalModel) {
9309
- return _this.removeInternalModel(internalModel);
9418
+ return _this2.removeInternalModel(internalModel);
9310
9419
  });
9311
9420
  };
9312
9421
 
9313
9422
  Relationship.prototype.addInternalModels = function addInternalModels(internalModels, idx) {
9314
- var _this2 = this;
9423
+ var _this3 = this;
9315
9424
 
9316
9425
  internalModels.forEach(function (internalModel) {
9317
- _this2.addInternalModel(internalModel, idx);
9426
+ _this3.addInternalModel(internalModel, idx);
9318
9427
  if (idx !== undefined) {
9319
9428
  idx++;
9320
9429
  }
@@ -9357,7 +9466,7 @@ define('ember-data/-private/system/relationships/state/relationship', ['exports'
9357
9466
  var _relationships = internalModel._implicitRelationships;
9358
9467
  var _relationship = _relationships[this.inverseKeyForImplicit];
9359
9468
  if (!_relationship) {
9360
- _relationship = _relationships[this.inverseKeyForImplicit] = new Relationship(this.store, internalModel, this.key, { options: { async: this.isAsync } });
9469
+ _relationship = _relationships[this.inverseKeyForImplicit] = new Relationship(this.store, internalModel, this.key, { options: { async: this.isAsync }, type: this.parentType });
9361
9470
  }
9362
9471
  _relationship.addCanonicalInternalModel(this.internalModel);
9363
9472
  }
@@ -9395,7 +9504,7 @@ define('ember-data/-private/system/relationships/state/relationship', ['exports'
9395
9504
  internalModel._relationships.get(this.inverseKey).addInternalModel(this.internalModel);
9396
9505
  } else {
9397
9506
  if (!internalModel._implicitRelationships[this.inverseKeyForImplicit]) {
9398
- internalModel._implicitRelationships[this.inverseKeyForImplicit] = new Relationship(this.store, internalModel, this.key, { options: { async: this.isAsync } });
9507
+ internalModel._implicitRelationships[this.inverseKeyForImplicit] = new Relationship(this.store, internalModel, this.key, { options: { async: this.isAsync }, type: this.parentType });
9399
9508
  }
9400
9509
  internalModel._implicitRelationships[this.inverseKeyForImplicit].addInternalModel(this.internalModel);
9401
9510
  }
@@ -9444,7 +9553,7 @@ define('ember-data/-private/system/relationships/state/relationship', ['exports'
9444
9553
  };
9445
9554
 
9446
9555
  Relationship.prototype.removeCompletelyFromInverse = function removeCompletelyFromInverse() {
9447
- var _this3 = this;
9556
+ var _this4 = this;
9448
9557
 
9449
9558
  if (!this.inverseKey) {
9450
9559
  return;
@@ -9459,7 +9568,7 @@ define('ember-data/-private/system/relationships/state/relationship', ['exports'
9459
9568
  var id = guidFor(inverseInternalModel);
9460
9569
 
9461
9570
  if (seen[id] === undefined) {
9462
- var relationship = inverseInternalModel._relationships.get(_this3.inverseKey);
9571
+ var relationship = inverseInternalModel._relationships.get(_this4.inverseKey);
9463
9572
  relationship.removeCompletelyFromOwn(internalModel);
9464
9573
  seen[id] = true;
9465
9574
  }
@@ -9467,6 +9576,32 @@ define('ember-data/-private/system/relationships/state/relationship', ['exports'
9467
9576
 
9468
9577
  this.members.forEach(unload);
9469
9578
  this.canonicalMembers.forEach(unload);
9579
+
9580
+ if (!this.isAsync) {
9581
+ this.clear();
9582
+ }
9583
+ };
9584
+
9585
+ Relationship.prototype.forAllMembers = function forAllMembers(callback) {
9586
+ var seen = Object.create(null);
9587
+
9588
+ for (var i = 0; i < this.members.list.length; i++) {
9589
+ var inverseInternalModel = this.members.list[i];
9590
+ var id = guidFor(inverseInternalModel);
9591
+ if (!seen[id]) {
9592
+ seen[id] = true;
9593
+ callback(inverseInternalModel);
9594
+ }
9595
+ }
9596
+
9597
+ for (var _i = 0; _i < this.canonicalMembers.list.length; _i++) {
9598
+ var _inverseInternalModel = this.canonicalMembers.list[_i];
9599
+ var _id = guidFor(_inverseInternalModel);
9600
+ if (!seen[_id]) {
9601
+ seen[_id] = true;
9602
+ callback(_inverseInternalModel);
9603
+ }
9604
+ }
9470
9605
  };
9471
9606
 
9472
9607
  Relationship.prototype.removeCompletelyFromOwn = function removeCompletelyFromOwn(internalModel) {
@@ -9489,8 +9624,8 @@ define('ember-data/-private/system/relationships/state/relationship', ['exports'
9489
9624
 
9490
9625
  //TODO(Igor) make this less abysmally slow
9491
9626
  this.members = this.canonicalMembers.copy();
9492
- for (var _i = 0; _i < newInternalModels.length; _i++) {
9493
- this.members.add(newInternalModels[_i]);
9627
+ for (var _i2 = 0; _i2 < newInternalModels.length; _i2++) {
9628
+ this.members.add(newInternalModels[_i2]);
9494
9629
  }
9495
9630
  };
9496
9631
 
@@ -9591,6 +9726,23 @@ define('ember-data/-private/system/relationships/state/relationship', ['exports'
9591
9726
  Relationship.prototype.destroy = function destroy() {};
9592
9727
 
9593
9728
  _createClass(Relationship, [{
9729
+ key: '_inverseMeta',
9730
+ get: function () {
9731
+ if (this.__inverseMeta === undefined) {
9732
+ var inverseMeta = null;
9733
+
9734
+ if (this.inverseKey) {
9735
+ var inverseModelClass = this.store.modelFor(this.relationshipMeta.type);
9736
+ var inverseRelationships = get(inverseModelClass, 'relationshipsByName');
9737
+ inverseMeta = inverseRelationships.get(this.inverseKey);
9738
+ }
9739
+
9740
+ this.__inverseMeta = inverseMeta;
9741
+ }
9742
+
9743
+ return this.__inverseMeta;
9744
+ }
9745
+ }, {
9594
9746
  key: 'parentType',
9595
9747
  get: function () {
9596
9748
  return this.internalModel.modelName;
@@ -18217,7 +18369,7 @@ define("ember-data/version", ["exports"], function (exports) {
18217
18369
  "use strict";
18218
18370
 
18219
18371
  exports.__esModule = true;
18220
- exports.default = "2.18.0";
18372
+ exports.default = "2.18.1";
18221
18373
  });
18222
18374
  define("ember-inflector", ["module", "exports", "ember-inflector/lib/system", "ember-inflector/lib/ext/string"], function (module, exports, _system) {
18223
18375
  "use strict";
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ember-data",
3
- "version": "2.18.0",
3
+ "version": "2.18.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: 2.18.0
4
+ version: 2.18.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: 2017-12-28 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