dist/globals/ember-data.prod.js in ember-data-source-2.14.4 vs dist/globals/ember-data.prod.js in ember-data-source-2.14.7
- old
+ new
@@ -4,11 +4,11 @@
/*!
* @overview Ember Data
* @copyright Copyright 2011-2017 Tilde Inc. and contributors.
* Portions Copyright 2011 LivingSocial Inc.
* @license Licensed under MIT license (see license.js)
- * @version 2.14.4
+ * @version 2.14.7
*/
var loader, define, requireModule, require, requirejs;
(function (global) {
@@ -3015,21 +3015,15 @@
internalModel.updateRecordArrays();
});
};
InternalModel.prototype._directlyRelatedInternalModels = function _directlyRelatedInternalModels() {
- var _this = this;
-
var array = [];
- this.type.eachRelationship(function (key, relationship) {
- if (_this._relationships.has(key)) {
- var _relationship = _this._relationships.get(key);
- var localRelationships = _relationship.members.toArray();
- var serverRelationships = _relationship.canonicalMembers.toArray();
-
- array = array.concat(localRelationships, serverRelationships);
- }
+ this._relationships.forEach(function (name, rel) {
+ var local = rel.members.toArray();
+ var server = rel.canonicalMembers.toArray();
+ array = array.concat(local, server);
});
return array;
};
InternalModel.prototype._allRelatedInternalModels = function _allRelatedInternalModels() {
@@ -3055,10 +3049,11 @@
};
InternalModel.prototype.unloadRecord = function unloadRecord() {
this.send('unloadRecord');
this.dematerializeRecord();
+
if (this._scheduledDestroy === null) {
this._scheduledDestroy = run.schedule('destroy', this, '_checkForOrphanedInternalModels');
}
};
@@ -3096,10 +3091,15 @@
};
InternalModel.prototype.destroy = function destroy() {
this.store._internalModelDestroyed(this);
+
+ this._relationships.forEach(function (name, rel) {
+ return rel.destroy();
+ });
+
this._isDestroyed = true;
};
InternalModel.prototype.eachAttribute = function eachAttribute(callback, binding) {
return this.modelClass.eachAttribute(callback, binding);
@@ -3224,16 +3224,10 @@
if (this.hasRecord) {
this._record.notifyHasManyAdded(key, record, idx);
}
};
- InternalModel.prototype.notifyHasManyRemoved = function notifyHasManyRemoved(key, record, idx) {
- if (this.hasRecord) {
- this._record.notifyHasManyRemoved(key, record, idx);
- }
- };
-
InternalModel.prototype.notifyBelongsToChanged = function notifyBelongsToChanged(key, record) {
if (this.hasRecord) {
this._record.notifyBelongsToChanged(key, record);
}
};
@@ -3263,11 +3257,11 @@
//TODO: Should probably move this to the state machine somehow
this.becameReady();
}
if (this.isNew()) {
- this.clearRelationships();
+ this.removeFromInverseRelationships(true);
}
if (this.isValid()) {
this._inFlightAttributes = null;
}
@@ -3379,51 +3373,72 @@
}
triggers.length = 0;
};
- InternalModel.prototype.clearRelationships = function clearRelationships() {
- var _this2 = this;
+ InternalModel.prototype.removeFromInverseRelationships = function removeFromInverseRelationships() {
+ var isNew = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
- this.eachRelationship(function (name, relationship) {
- if (_this2._relationships.has(name)) {
- var rel = _this2._relationships.get(name);
+ this._relationships.forEach(function (name, rel) {
+ rel.removeCompletelyFromInverse();
+ if (isNew === true) {
rel.clear();
- rel.removeInverseRelationships();
}
});
- Object.keys(this._implicitRelationships).forEach(function (key) {
- _this2._implicitRelationships[key].clear();
- _this2._implicitRelationships[key].removeInverseRelationships();
+
+ var implicitRelationships = this._implicitRelationships;
+ this.__implicitRelationships = null;
+
+ Object.keys(implicitRelationships).forEach(function (key) {
+ var rel = implicitRelationships[key];
+
+ rel.removeCompletelyFromInverse();
+ if (isNew === true) {
+ rel.clear();
+ }
});
};
InternalModel.prototype.destroyRelationships = function destroyRelationships() {
- var _this3 = this;
+ var _this = this;
- this.eachRelationship(function (name, relationship) {
- if (_this3._relationships.has(name)) {
- var rel = _this3._relationships.get(name);
+ this._relationships.forEach(function (name, rel) {
+ if (rel._inverseIsAsync()) {
+ rel.removeInternalModelFromInverse(_this);
rel.removeInverseRelationships();
+ } else {
+ rel.removeCompletelyFromInverse();
}
});
- Object.keys(this._implicitRelationships).forEach(function (key) {
- _this3._implicitRelationships[key].removeInverseRelationships();
+
+ var implicitRelationships = this._implicitRelationships;
+ this.__implicitRelationships = null;
+ Object.keys(implicitRelationships).forEach(function (key) {
+ var rel = implicitRelationships[key];
+
+ if (rel._inverseIsAsync()) {
+ rel.removeInternalModelFromInverse(_this);
+ rel.removeInverseRelationships();
+ } else {
+ rel.removeCompletelyFromInverse();
+ }
+
+ rel.destroy();
});
};
InternalModel.prototype.preloadData = function preloadData(preload) {
- var _this4 = this;
+ var _this2 = this;
//TODO(Igor) consider the polymorphic case
Object.keys(preload).forEach(function (key) {
var preloadValue = get(preload, key);
- var relationshipMeta = _this4.modelClass.metaForProperty(key);
+ var relationshipMeta = _this2.modelClass.metaForProperty(key);
if (relationshipMeta.isRelationship) {
- _this4._preloadRelationship(key, preloadValue);
+ _this2._preloadRelationship(key, preloadValue);
} else {
- _this4._data[key] = preloadValue;
+ _this2._data[key] = preloadValue;
}
});
};
InternalModel.prototype._preloadRelationship = function _preloadRelationship(key, preloadValue) {
@@ -3623,11 +3638,11 @@
InternalModel.prototype.toString = function toString() {
return '<' + this.modelName + ':' + this.id + '>';
};
InternalModel.prototype.referenceFor = function referenceFor(kind, name) {
- var _this5 = this;
+ var _this3 = this;
var reference = this.references[name];
if (!reference) {
var relationship = this._relationships.get(name);
@@ -5448,11 +5463,11 @@
saved: {
// FLAGS
isDirty: false,
setup: function (internalModel) {
- internalModel.clearRelationships();
+ internalModel.removeFromInverseRelationships();
},
invokeLifecycleCallbacks: function (internalModel) {
internalModel.triggerLater('didDelete', internalModel);
internalModel.triggerLater('didCommit', internalModel);
},
@@ -8449,10 +8464,23 @@
BelongsToRelationship.prototype.inverseDidDematerialize = function inverseDidDematerialize() {
this.notifyBelongsToChanged();
};
+ BelongsToRelationship.prototype.removeCompletelyFromOwn = function removeCompletelyFromOwn(internalModel) {
+ _Relationship.prototype.removeCompletelyFromOwn.call(this, internalModel);
+
+ if (this.canonicalState === internalModel) {
+ this.canonicalState = null;
+ }
+
+ if (this.inverseInternalModel === internalModel) {
+ this.inverseInternalModel = null;
+ this.notifyBelongsToChanged();
+ }
+ };
+
BelongsToRelationship.prototype.flushCanonical = function flushCanonical() {
//temporary fix to not remove newly created records if server returned null.
//TODO remove once we have proper diffing
if (this.inverseInternalModel && this.inverseInternalModel.isNew() && !this.canonicalState) {
return;
@@ -8653,10 +8681,17 @@
Relationships.prototype.has = function has(key) {
return !!this.initializedRelationships[key];
};
+ Relationships.prototype.forEach = function forEach(cb) {
+ var rels = this.initializedRelationships;
+ Object.keys(rels).forEach(function (name) {
+ cb(name, rels[name]);
+ });
+ };
+
Relationships.prototype.get = function get(key) {
var relationships = this.initializedRelationships;
var relationship = relationships[key];
var internalModel = this.internalModel;
@@ -8836,10 +8871,30 @@
this.canonicalState.splice(i, 1);
}
_Relationship.prototype.removeCanonicalInternalModelFromOwn.call(this, internalModel, idx);
};
+ ManyRelationship.prototype.removeCompletelyFromOwn = function removeCompletelyFromOwn(internalModel) {
+ _Relationship.prototype.removeCompletelyFromOwn.call(this, internalModel);
+
+ var canonicalIndex = this.canonicalState.indexOf(internalModel);
+
+ if (canonicalIndex !== -1) {
+ this.canonicalState.splice(canonicalIndex, 1);
+ }
+
+ var manyArray = this._manyArray;
+
+ if (manyArray) {
+ var idx = manyArray.currentState.indexOf(internalModel);
+
+ if (idx !== -1) {
+ manyArray.internalReplace(idx, 1);
+ }
+ }
+ };
+
ManyRelationship.prototype.flushCanonical = function flushCanonical() {
if (this._manyArray) {
this._manyArray.flushCanonical();
}
_Relationship.prototype.flushCanonical.call(this);
@@ -8912,37 +8967,45 @@
this.addCanonicalInternalModel(internalModel, i);
}
};
ManyRelationship.prototype.setInitialInternalModels = function setInitialInternalModels(internalModels) {
- var _this2 = this;
+ var _canonicalState;
- if (!internalModels) {
+ if (Array.isArray(internalModels) === false || internalModels.length === 0) {
return;
}
- var args = [0, this.canonicalState.length].concat(internalModels);
- this.canonicalState.splice.apply(this.canonicalState, args);
- internalModels.forEach(function (internalModel) {
- _this2.canonicalMembers.add(internalModel);
- _this2.members.add(internalModel);
- _this2.setupInverseRelationship(internalModel);
- });
+ var forCanonical = [];
+
+ for (var i = 0; i < internalModels.length; i++) {
+ var internalModel = internalModels[i];
+ if (this.canonicalMembers.has(internalModel)) {
+ continue;
+ }
+
+ forCanonical.push(internalModel);
+ this.canonicalMembers.add(internalModel);
+ this.members.add(internalModel);
+ this.setupInverseRelationship(internalModel);
+ }
+
+ (_canonicalState = this.canonicalState).splice.apply(_canonicalState, [0, this.canonicalState.length].concat(forCanonical));
};
ManyRelationship.prototype.fetchLink = function fetchLink() {
- var _this3 = this;
+ var _this2 = this;
return this.store.findHasMany(this.internalModel, this.link, this.relationshipMeta).then(function (records) {
if (records.hasOwnProperty('meta')) {
- _this3.updateMeta(records.meta);
+ _this2.updateMeta(records.meta);
}
- _this3.store._backburner.join(function () {
- _this3.updateInternalModelsFromAdapter(records);
- _this3.manyArray.set('isLoaded', true);
+ _this2.store._backburner.join(function () {
+ _this2.updateInternalModelsFromAdapter(records);
+ _this2.manyArray.set('isLoaded', true);
});
- return _this3.manyArray;
+ return _this2.manyArray;
});
};
ManyRelationship.prototype.findRecords = function findRecords() {
var manyArray = this.manyArray;
@@ -8961,22 +9024,22 @@
ManyRelationship.prototype.notifyHasManyChanged = function notifyHasManyChanged() {
this.internalModel.notifyHasManyAdded(this.key);
};
ManyRelationship.prototype.getRecords = function getRecords() {
- var _this4 = this;
+ var _this3 = this;
//TODO(Igor) sync server here, once our syncing is not stupid
var manyArray = this.manyArray;
if (this.isAsync) {
var promise = void 0;
if (this.link) {
if (this.hasLoaded) {
promise = this.findRecords();
} else {
promise = this.findLink().then(function () {
- return _this4.findRecords();
+ return _this3.findRecords();
});
}
} else {
promise = this.findRecords();
}
@@ -8999,10 +9062,24 @@
} else {
this.updateInternalModelsFromAdapter(internalModels);
}
};
+ ManyRelationship.prototype.destroy = function destroy() {
+ _Relationship.prototype.destroy.call(this);
+ var manyArray = this._manyArray;
+ if (manyArray) {
+ manyArray.destroy();
+ }
+
+ var proxy = this.__loadingPromise;
+
+ if (proxy) {
+ proxy.destroy();
+ }
+ };
+
_createClass(ManyRelationship, [{
key: '_loadingPromise',
get: function () {
return this.__loadingPromise;
}
@@ -9040,11 +9117,11 @@
}
return set;
}
});
-define('ember-data/-private/system/relationships/state/relationship', ['exports', 'ember-data/-private/system/ordered-set', 'ember-data/-private/system/normalize-link'], function (exports, _orderedSet, _normalizeLink2) {
+define('ember-data/-private/system/relationships/state/relationship', ['exports', 'ember-data/-private/system/ordered-set', 'ember-data/-private/system/normalize-link', 'ember'], function (exports, _orderedSet, _normalizeLink2, _ember) {
'use strict';
exports.__esModule = true;
function _classCallCheck(instance, Constructor) {
@@ -9069,10 +9146,12 @@
if (staticProps) defineProperties(Constructor, staticProps);
return Constructor;
};
}();
+ var guidFor = _ember.default.guidFor;
+
var Relationship = function () {
function Relationship(store, internalModel, inverseKey, relationshipMeta) {
var async = relationshipMeta.options.async;
var polymorphic = relationshipMeta.options.polymorphic;
this.members = new _orderedSet.default();
@@ -9091,10 +9170,17 @@
this.meta = null;
this.hasData = false;
this.hasLoaded = false;
}
+ Relationship.prototype._inverseIsAsync = function _inverseIsAsync() {
+ if (!this.inverseKey || !this.inverseInternalModel) {
+ return false;
+ }
+ return this.inverseInternalModel._relationships.get(this.inverseKey).isAsync;
+ };
+
Relationship.prototype.removeInverseRelationships = function removeInverseRelationships() {
var _this = this;
if (!this.inverseKey) {
return;
@@ -9185,11 +9271,11 @@
}
} else {
var _relationships = internalModel._implicitRelationships;
var _relationship = _relationships[this.inverseKeyForImplicit];
if (!_relationship) {
- _relationship = _relationships[this.inverseKeyForImplicit] = new Relationship(this.store, internalModel, this.key, { options: {} });
+ _relationship = _relationships[this.inverseKeyForImplicit] = new Relationship(this.store, internalModel, this.key, { options: { async: this.isAsync } });
}
_relationship.addCanonicalInternalModel(this.internalModel);
}
};
@@ -9223,11 +9309,11 @@
this.notifyRecordRelationshipAdded(internalModel, idx);
if (this.inverseKey) {
internalModel._relationships.get(this.inverseKey).addInternalModel(this.internalModel);
} else {
if (!internalModel._implicitRelationships[this.inverseKeyForImplicit]) {
- internalModel._implicitRelationships[this.inverseKeyForImplicit] = new Relationship(this.store, internalModel, this.key, { options: {} });
+ internalModel._implicitRelationships[this.inverseKeyForImplicit] = new Relationship(this.store, internalModel, this.key, { options: { async: this.isAsync } });
}
internalModel._implicitRelationships[this.inverseKeyForImplicit].addInternalModel(this.internalModel);
}
this.internalModel.updateRecordArrays();
}
@@ -9255,11 +9341,10 @@
}
};
Relationship.prototype.removeInternalModelFromOwn = function removeInternalModelFromOwn(internalModel) {
this.members.delete(internalModel);
- this.notifyRecordRelationshipRemoved(internalModel);
this.internalModel.updateRecordArrays();
};
Relationship.prototype.removeCanonicalInternalModelFromInverse = function removeCanonicalInternalModelFromInverse(internalModel) {
var inverseRelationship = internalModel._relationships.get(this.inverseKey);
@@ -9272,10 +9357,42 @@
Relationship.prototype.removeCanonicalInternalModelFromOwn = function removeCanonicalInternalModelFromOwn(internalModel) {
this.canonicalMembers.delete(internalModel);
this.flushCanonicalLater();
};
+ Relationship.prototype.removeCompletelyFromInverse = function removeCompletelyFromInverse() {
+ var _this4 = this;
+
+ if (!this.inverseKey) {
+ return;
+ }
+
+ // we actually want a union of members and canonicalMembers
+ // they should be disjoint but currently are not due to a bug
+ var seen = Object.create(null);
+ var internalModel = this.internalModel;
+
+ var unload = function (inverseInternalModel) {
+ var id = guidFor(inverseInternalModel);
+
+ if (seen[id] === undefined) {
+ var relationship = inverseInternalModel._relationships.get(_this4.inverseKey);
+ relationship.removeCompletelyFromOwn(internalModel);
+ seen[id] = true;
+ }
+ };
+
+ this.members.forEach(unload);
+ this.canonicalMembers.forEach(unload);
+ };
+
+ Relationship.prototype.removeCompletelyFromOwn = function removeCompletelyFromOwn(internalModel) {
+ this.canonicalMembers.delete(internalModel);
+ this.members.delete(internalModel);
+ this.internalModel.updateRecordArrays();
+ };
+
Relationship.prototype.flushCanonical = function flushCanonical() {
var list = this.members.list;
this.willSync = false;
//a hack for not removing new internalModels
//TODO remove once we have proper diffing
@@ -9326,12 +9443,10 @@
this.computeChanges(internalModels);
};
Relationship.prototype.notifyRecordRelationshipAdded = function notifyRecordRelationshipAdded() {};
- Relationship.prototype.notifyRecordRelationshipRemoved = function notifyRecordRelationshipRemoved() {};
-
Relationship.prototype.setHasData = function setHasData(value) {
this.hasData = value;
};
Relationship.prototype.setHasLoaded = function setHasLoaded(value) {
@@ -9378,10 +9493,12 @@
}
};
Relationship.prototype.updateData = function updateData() {};
+ Relationship.prototype.destroy = function destroy() {};
+
_createClass(Relationship, [{
key: 'parentType',
get: function () {
return this.internalModel.modelName;
}
@@ -9899,11 +10016,11 @@
`store#push` that will deserialize payloads if the
Serializer implements a `pushPayload` method.
Note: When creating a new record using any of the above methods
Ember Data will update `DS.RecordArray`s such as those returned by
- `store#peekAll()`, `store#findAll()` or `store#filter()`. This means any
+ `store#peekAll()` or `store#findAll()`. This means any
data bindings or computed properties that depend on the RecordArray
will automatically be synced to include the new or updated record
values.
@class Store
@@ -14850,11 +14967,11 @@
name: 'data-adapter',
before: 'store',
initialize: function () {}
};
});
-define('ember-data/initializers/ember-data', ['exports', 'ember-data/setup-container', 'ember-data/index'], function (exports, _setupContainer) {
+define('ember-data/initializers/ember-data', ['exports', 'ember-data/setup-container', 'ember-data'], function (exports, _setupContainer) {
'use strict';
exports.__esModule = true;
exports.default = {
name: 'ember-data',
@@ -17637,10 +17754,10 @@
});
define("ember-data/version", ["exports"], function (exports) {
"use strict";
exports.__esModule = true;
- exports.default = "2.14.4";
+ exports.default = "2.14.7";
});
define("ember-inflector", ["module", "exports", "ember", "ember-inflector/lib/system", "ember-inflector/lib/ext/string"], function (module, exports, _ember, _system) {
"use strict";
exports.__esModule = true;