dist/globals/ember-data.prod.js in ember-data-source-2.16.1 vs dist/globals/ember-data.prod.js in ember-data-source-2.16.4
- 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.16.1
+ * @version 2.16.4
*/
var loader, define, requireModule, require, requirejs;
(function (global) {
@@ -4798,10 +4798,14 @@
// If it is, get the metadata for the relationship. This is
// populated by the `DS.belongsTo` helper when it is creating
// the computed property.
var meta = value.meta();
+ /*
+ This is buggy because if the parent has never been looked up
+ via `modelFor` it will not have `modelName` set.
+ */
meta.parentType = proto.constructor;
}
}
});
}
@@ -7581,25 +7585,19 @@
}
return modelName;
}
function relationshipFromMeta(meta) {
- var result = {
+ return {
key: meta.key,
kind: meta.kind,
type: typeForRelationshipMeta(meta),
options: meta.options,
name: meta.name,
parentType: meta.parentType,
isRelationship: true
};
-
- if (false) {
- result.parentType = meta.parentType;
- }
-
- return result;
}
});
define('ember-data/-private/system/relationships/belongs-to', ['exports', 'ember', 'ember-data/-private/system/normalize-model-name'], function (exports, _ember, _normalizeModelName) {
'use strict';
@@ -8001,11 +7999,12 @@
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
- var _get = _ember.default.get;
+ var get = _ember.default.get;
+ var assert = _ember.default.assert;
/**
Manages relationship payloads for a given store, for uninitialized
relationships. Acts as a single source of truth (of payloads) for both sides
of an uninitialized relationship so they can agree on the most up-to-date
@@ -8062,10 +8061,11 @@
var RelationshipPayloadsManager = function () {
function RelationshipPayloadsManager(store) {
this._store = store;
// cache of `RelationshipPayload`s
this._cache = Object.create(null);
+ this._inverseLookupCache = new _relationshipPayloads.TypeCache();
}
/**
Find the payload for the given relationship of the given model.
Returns the payload for the given relationship, whether raw or computed from
@@ -8082,90 +8082,194 @@
@method
*/
RelationshipPayloadsManager.prototype.get = function get(modelName, id, relationshipName) {
- var modelClass = this._store._modelFor(modelName);
- var relationshipsByName = _get(modelClass, 'relationshipsByName');
- var relationshipPayloads = this._getRelationshipPayloads(modelName, relationshipName, modelClass, relationshipsByName, false);
+ var relationshipPayloads = this._getRelationshipPayloads(modelName, relationshipName, false);
return relationshipPayloads && relationshipPayloads.get(modelName, id, relationshipName);
};
RelationshipPayloadsManager.prototype.push = function push(modelName, id, relationshipsData) {
var _this = this;
if (!relationshipsData) {
return;
}
- var modelClass = this._store._modelFor(modelName);
- var relationshipsByName = _get(modelClass, 'relationshipsByName');
Object.keys(relationshipsData).forEach(function (key) {
- var relationshipPayloads = _this._getRelationshipPayloads(modelName, key, modelClass, relationshipsByName, true);
+ var relationshipPayloads = _this._getRelationshipPayloads(modelName, key, true);
if (relationshipPayloads) {
relationshipPayloads.push(modelName, id, key, relationshipsData[key]);
}
});
};
RelationshipPayloadsManager.prototype.unload = function unload(modelName, id) {
var _this2 = this;
var modelClass = this._store._modelFor(modelName);
- var relationshipsByName = _get(modelClass, 'relationshipsByName');
+ var relationshipsByName = get(modelClass, 'relationshipsByName');
relationshipsByName.forEach(function (_, relationshipName) {
- var relationshipPayloads = _this2._getRelationshipPayloads(modelName, relationshipName, modelClass, relationshipsByName, false);
+ var relationshipPayloads = _this2._getRelationshipPayloads(modelName, relationshipName, false);
if (relationshipPayloads) {
relationshipPayloads.unload(modelName, id, relationshipName);
}
});
};
- RelationshipPayloadsManager.prototype._getRelationshipPayloads = function _getRelationshipPayloads(modelName, relationshipName, modelClass, relationshipsByName, init) {
- if (!relationshipsByName.has(relationshipName)) {
+ RelationshipPayloadsManager.prototype._getRelationshipPayloads = function _getRelationshipPayloads(modelName, relationshipName, init) {
+ var relInfo = this.getRelationshipInfo(modelName, relationshipName);
+
+ if (relInfo === null) {
return;
}
- var key = modelName + ':' + relationshipName;
- if (!this._cache[key] && init) {
- return this._initializeRelationshipPayloads(modelName, relationshipName, modelClass, relationshipsByName);
+ var cache = this._cache[relInfo.lhs_key];
+
+ if (!cache && init) {
+ return this._initializeRelationshipPayloads(relInfo);
}
- return this._cache[key];
+ return cache;
};
- RelationshipPayloadsManager.prototype._initializeRelationshipPayloads = function _initializeRelationshipPayloads(modelName, relationshipName, modelClass, relationshipsByName) {
+ RelationshipPayloadsManager.prototype.getRelationshipInfo = function getRelationshipInfo(modelName, relationshipName) {
+ var inverseCache = this._inverseLookupCache;
+ var store = this._store;
+ var cached = inverseCache.get(modelName, relationshipName);
+
+ // CASE: We have a cached resolution (null if no relationship exists)
+ if (cached !== undefined) {
+ return cached;
+ }
+
+ var modelClass = store._modelFor(modelName);
+ var relationshipsByName = get(modelClass, 'relationshipsByName');
+
+ // CASE: We don't have a relationship at all
+ if (!relationshipsByName.has(relationshipName)) {
+ inverseCache.set(modelName, relationshipName, null);
+ return null;
+ }
+
+ var inverseMeta = modelClass.inverseFor(relationshipName, store);
var relationshipMeta = relationshipsByName.get(relationshipName);
- var inverseMeta = modelClass.inverseFor(relationshipName, this._store);
+ var selfIsPolymorphic = relationshipMeta.options !== undefined && relationshipMeta.options.polymorphic === true;
+ var inverseBaseModelName = relationshipMeta.type;
- var inverseModelName = void 0;
- var inverseRelationshipName = void 0;
- var inverseRelationshipMeta = void 0;
+ // CASE: We have no inverse
+ if (!inverseMeta) {
+ var _info = {
+ lhs_key: modelName + ':' + relationshipName,
+ lhs_modelNames: [modelName],
+ lhs_baseModelName: modelName,
+ lhs_relationshipName: relationshipName,
+ lhs_relationshipMeta: relationshipMeta,
+ lhs_isPolymorphic: selfIsPolymorphic,
+ rhs_key: '',
+ rhs_modelNames: [],
+ rhs_baseModelName: inverseBaseModelName,
+ rhs_relationshipName: '',
+ rhs_relationshipMeta: null,
+ rhs_isPolymorphic: false,
+ hasInverse: false,
+ isSelfReferential: false, // modelName === inverseBaseModelName,
+ isReflexive: false
+ };
- // figure out the inverse relationship; we need two things
- // a) the inverse model name
- //- b) the name of the inverse relationship
- if (inverseMeta) {
- inverseRelationshipName = inverseMeta.name;
- inverseModelName = relationshipMeta.type;
- inverseRelationshipMeta = _get(inverseMeta.type, 'relationshipsByName').get(inverseRelationshipName);
- } else {
- // relationship has no inverse
- inverseModelName = inverseRelationshipName = '';
- inverseRelationshipMeta = null;
+ inverseCache.set(modelName, relationshipName, _info);
+
+ return _info;
}
- var lhsKey = modelName + ':' + relationshipName;
- var rhsKey = inverseModelName + ':' + inverseRelationshipName;
+ // CASE: We do have an inverse
+ var inverseRelationshipName = inverseMeta.name;
+ var inverseRelationshipMeta = get(inverseMeta.type, 'relationshipsByName').get(inverseRelationshipName);
+ var baseModelName = inverseRelationshipMeta.type;
+ var isSelfReferential = baseModelName === inverseBaseModelName;
+
+ // TODO we want to assert this but this breaks all of our shoddily written tests
+ /*
+ if (DEBUG) {
+ let inverseDoubleCheck = inverseMeta.type.inverseFor(inverseRelationshipName, store);
+ assert(`The ${inverseBaseModelName}:${inverseRelationshipName} relationship declares 'inverse: null', but it was resolved as the inverse for ${baseModelName}:${relationshipName}.`, inverseDoubleCheck);
+ }
+ */
+
+ // CASE: We may have already discovered the inverse for the baseModelName
+ // CASE: We have already discovered the inverse
+ cached = inverseCache.get(baseModelName, relationshipName) || inverseCache.get(inverseBaseModelName, inverseRelationshipName);
+ if (cached) {
+ // TODO this assert can be removed if the above assert is enabled
+ assert('The ' + inverseBaseModelName + ':' + inverseRelationshipName + ' relationship declares \'inverse: null\', but it was resolved as the inverse for ' + baseModelName + ':' + relationshipName + '.', cached.hasInverse !== false);
+
+ var isLHS = cached.lhs_baseModelName === baseModelName;
+ var modelNames = isLHS ? cached.lhs_modelNames : cached.rhs_modelNames;
+ // make this lookup easier in the future by caching the key
+ modelNames.push(modelName);
+ inverseCache.set(modelName, relationshipName, cached);
+
+ return cached;
+ }
+
+ var info = {
+ lhs_key: baseModelName + ':' + relationshipName,
+ lhs_modelNames: [modelName],
+ lhs_baseModelName: baseModelName,
+ lhs_relationshipName: relationshipName,
+ lhs_relationshipMeta: relationshipMeta,
+ lhs_isPolymorphic: selfIsPolymorphic,
+ rhs_key: inverseBaseModelName + ':' + inverseRelationshipName,
+ rhs_modelNames: [],
+ rhs_baseModelName: inverseBaseModelName,
+ rhs_relationshipName: inverseRelationshipName,
+ rhs_relationshipMeta: inverseRelationshipMeta,
+ rhs_isPolymorphic: inverseRelationshipMeta.options !== undefined && inverseRelationshipMeta.options.polymorphic === true,
+ hasInverse: true,
+ isSelfReferential: isSelfReferential,
+ isReflexive: isSelfReferential && relationshipName === inverseRelationshipName
+ };
+
+ // Create entries for the baseModelName as well as modelName to speed up
+ // inverse lookups
+ inverseCache.set(baseModelName, relationshipName, info);
+ inverseCache.set(modelName, relationshipName, info);
+
+ // Greedily populate the inverse
+ inverseCache.set(inverseBaseModelName, inverseRelationshipName, info);
+
+ return info;
+ };
+
+ RelationshipPayloadsManager.prototype._initializeRelationshipPayloads = function _initializeRelationshipPayloads(relInfo) {
+ var lhsKey = relInfo.lhs_key;
+ var rhsKey = relInfo.rhs_key;
+ var existingPayloads = this._cache[lhsKey];
+
+ if (relInfo.hasInverse === true && relInfo.rhs_isPolymorphic === true) {
+ existingPayloads = this._cache[rhsKey];
+
+ if (existingPayloads !== undefined) {
+ this._cache[lhsKey] = existingPayloads;
+ return existingPayloads;
+ }
+ }
+
// populate the cache for both sides of the relationship, as they both use
// the same `RelationshipPayloads`.
//
// This works out better than creating a single common key, because to
// compute that key we would need to do work to look up the inverse
//
- return this._cache[lhsKey] = this._cache[rhsKey] = new _relationshipPayloads.default(this._store, modelName, relationshipName, relationshipMeta, inverseModelName, inverseRelationshipName, inverseRelationshipMeta);
+ var cache = this._cache[lhsKey] = new _relationshipPayloads.default(relInfo);
+
+ if (relInfo.hasInverse === true) {
+ this._cache[rhsKey] = cache;
+ }
+
+ return cache;
};
return RelationshipPayloadsManager;
}();
@@ -8174,16 +8278,10 @@
define('ember-data/-private/system/relationships/relationship-payloads', ['exports'], function (exports) {
'use strict';
exports.__esModule = true;
- function _classCallCheck(instance, Constructor) {
- if (!(instance instanceof Constructor)) {
- throw new TypeError("Cannot call a class as a function");
- }
- }
-
var _createClass = function () {
function defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
@@ -8198,65 +8296,87 @@
if (staticProps) defineProperties(Constructor, staticProps);
return Constructor;
};
}();
- var RelationshipPayloads = function () {
- function RelationshipPayloads(store, modelName, relationshipName, relationshipMeta, inverseModelName, inverseRelationshipName, inverseRelationshipMeta) {
- this._store = store;
+ function _classCallCheck(instance, Constructor) {
+ if (!(instance instanceof Constructor)) {
+ throw new TypeError("Cannot call a class as a function");
+ }
+ }
- this._lhsModelName = modelName;
- this._lhsRelationshipName = relationshipName;
- this._lhsRelationshipMeta = relationshipMeta;
+ var TypeCache = exports.TypeCache = function () {
+ function TypeCache() {
+ this.types = Object.create(null);
+ }
- this._rhsModelName = inverseModelName;
- this._rhsRelationshipName = inverseRelationshipName;
- this._rhsRelationshipMeta = inverseRelationshipMeta;
+ TypeCache.prototype.get = function get(modelName, id) {
+ var types = this.types;
- // a map of id -> payloads for the left hand side of the relationship.
- this._lhsPayloads = Object.create(null);
- if (modelName !== inverseModelName || relationshipName !== inverseRelationshipName) {
- // The common case of a non-reflexive relationship, or a reflexive
- // relationship whose inverse is not itself
- this._rhsPayloads = Object.create(null);
- this._isReflexive = false;
- } else {
- // Edge case when we have a reflexive relationship to itself
- // eg user hasMany friends inverse friends
- //
- // In this case there aren't really two sides to the relationship, but
- // we set `_rhsPayloads = _lhsPayloads` to make things easier to reason
- // about
- this._rhsPayloads = this._lhsPayloads;
- this._isReflexive = true;
+
+ if (types[modelName] !== undefined) {
+ return types[modelName][id];
}
+ };
+ TypeCache.prototype.set = function set(modelName, id, payload) {
+ var types = this.types;
+
+ var typeMap = types[modelName];
+
+ if (typeMap === undefined) {
+ typeMap = types[modelName] = Object.create(null);
+ }
+
+ typeMap[id] = payload;
+ };
+
+ TypeCache.prototype.delete = function _delete(modelName, id) {
+ var types = this.types;
+
+
+ if (types[modelName] !== undefined) {
+ delete types[modelName][id];
+ }
+ };
+
+ return TypeCache;
+ }();
+
+ var RelationshipPayloads = function () {
+ function RelationshipPayloads(relInfo) {
+ this._relInfo = relInfo;
+
+ // a map of id -> payloads for the left hand side of the relationship.
+ this.lhs_payloads = new TypeCache();
+ this.rhs_payloads = relInfo.isReflexive ? this.lhs_payloads : new TypeCache();
+
// When we push relationship payloads, just stash them in a queue until
// somebody actually asks for one of them.
//
// This is a queue of the relationship payloads that have been pushed for
// either side of this relationship
this._pendingPayloads = [];
}
/**
- Get the payload for the relationship of an individual record.
- This might return the raw payload as pushed into the store, or one computed
- from the payload of the inverse relationship.
- @method
- */
+ Get the payload for the relationship of an individual record.
+ This might return the raw payload as pushed into the store, or one computed
+ from the payload of the inverse relationship.
+ @method
+ */
RelationshipPayloads.prototype.get = function get(modelName, id, relationshipName) {
this._flushPending();
if (this._isLHS(modelName, relationshipName)) {
- return this._lhsPayloads[id];
+ return this.lhs_payloads.get(modelName, id);
} else {
- (false && Ember.assert(modelName + ':' + relationshipName + ' is not either side of this relationship, ' + this._lhsModelName + ':' + this._lhsRelationshipName + '<->' + this._rhsModelName + ':' + this._rhsRelationshipName, this._isRHS(modelName, relationshipName)));
+ (false && Ember.assert(modelName + ':' + relationshipName + ' is not either side of this relationship, ' + this._relInfo.lhs_key + '<->' + this._relInfo.rhs_key, this._isRHS(modelName, relationshipName)));
- return this._rhsPayloads[id];
+ return this.rhs_payloads.get(modelName, id);
}
};
RelationshipPayloads.prototype.push = function push(modelName, id, relationshipName, relationshipData) {
this._pendingPayloads.push([modelName, id, relationshipName, relationshipData]);
@@ -8264,24 +8384,44 @@
RelationshipPayloads.prototype.unload = function unload(modelName, id, relationshipName) {
this._flushPending();
if (this._isLHS(modelName, relationshipName)) {
- delete this._lhsPayloads[id];
+ delete this.lhs_payloads.delete(modelName, id);
} else {
- (false && Ember.assert(modelName + ':' + relationshipName + ' is not either side of this relationship, ' + this._lhsModelName + ':' + this._lhsRelationshipName + '<->' + this._rhsModelName + ':' + this._rhsRelationshipName, this._isRHS(modelName, relationshipName)));
+ (false && Ember.assert(modelName + ':' + relationshipName + ' is not either side of this relationship, ' + this._relInfo.lhs_baseModelName + ':' + this._relInfo.lhs_relationshipName + '<->' + this._relInfo.rhs_baseModelName + ':' + this._relInfo.rhs_relationshipName, this._isRHS(modelName, relationshipName)));
- delete this._rhsPayloads[id];
+ delete this.rhs_payloads.delete(modelName, id);
}
};
RelationshipPayloads.prototype._isLHS = function _isLHS(modelName, relationshipName) {
- return modelName === this._lhsModelName && relationshipName === this._lhsRelationshipName;
+ var relInfo = this._relInfo;
+ var isSelfReferential = relInfo.isSelfReferential;
+ var isRelationship = relationshipName === relInfo.lhs_relationshipName;
+
+ if (isRelationship === true) {
+ return isSelfReferential === true || // itself
+ modelName === relInfo.lhs_baseModelName || // base or non-polymorphic
+ relInfo.lhs_modelNames.indexOf(modelName) !== -1; // polymorphic
+ }
+
+ return false;
};
RelationshipPayloads.prototype._isRHS = function _isRHS(modelName, relationshipName) {
- return modelName === this._rhsModelName && relationshipName === this._rhsRelationshipName;
+ var relInfo = this._relInfo;
+ var isSelfReferential = relInfo.isSelfReferential;
+ var isRelationship = relationshipName === relInfo.rhs_relationshipName;
+
+ if (isRelationship === true) {
+ return isSelfReferential === true || // itself
+ modelName === relInfo.rhs_baseModelName || // base or non-polymorphic
+ relInfo.rhs_modelNames.indexOf(modelName) !== -1; // polymorphic
+ }
+
+ return false;
};
RelationshipPayloads.prototype._flushPending = function _flushPending() {
if (this._pendingPayloads.length === 0) {
return;
@@ -8298,30 +8438,32 @@
var inverseRelationshipData = {
data: {
id: id,
type: modelName
}
+ };
- // start flushing this individual payload. The logic is the same whether
- // it's for the left hand side of the relationship or the right hand side,
- // except the role of primary and inverse idToPayloads is reversed
- //
- };var previousPayload = void 0;
- var idToPayloads = void 0;
- var inverseIdToPayloads = void 0;
+ // start flushing this individual payload. The logic is the same whether
+ // it's for the left hand side of the relationship or the right hand side,
+ // except the role of primary and inverse idToPayloads is reversed
+ //
+ var previousPayload = void 0;
+ var payloadMap = void 0;
+ var inversePayloadMap = void 0;
var inverseIsMany = void 0;
+
if (this._isLHS(modelName, relationshipName)) {
- previousPayload = this._lhsPayloads[id];
- idToPayloads = this._lhsPayloads;
- inverseIdToPayloads = this._rhsPayloads;
+ previousPayload = this.lhs_payloads.get(modelName, id);
+ payloadMap = this.lhs_payloads;
+ inversePayloadMap = this.rhs_payloads;
inverseIsMany = this._rhsRelationshipIsMany;
} else {
- (false && Ember.assert(modelName + ':' + relationshipName + ' is not either side of this relationship, ' + this._lhsModelName + ':' + this._lhsRelationshipName + '<->' + this._rhsModelName + ':' + this._rhsRelationshipName, this._isRHS(modelName, relationshipName)));
+ (false && Ember.assert(modelName + ':' + relationshipName + ' is not either side of this relationship, ' + this._relInfo.lhs_key + '<->' + this._relInfo.rhs_key, this._isRHS(modelName, relationshipName)));
- previousPayload = this._rhsPayloads[id];
- idToPayloads = this._rhsPayloads;
- inverseIdToPayloads = this._lhsPayloads;
+ previousPayload = this.rhs_payloads.get(modelName, id);
+ payloadMap = this.rhs_payloads;
+ inversePayloadMap = this.lhs_payloads;
inverseIsMany = this._lhsRelationshipIsMany;
}
// actually flush this individual payload
//
@@ -8361,67 +8503,69 @@
// only remove relationship information before adding if there is relationshipData.data
// * null is considered new information "empty", and it should win
// * undefined is NOT considered new information, we should keep original state
// * anything else is considered new information, and it should win
if (relationshipData.data !== undefined) {
- this._removeInverse(id, previousPayload, inverseIdToPayloads);
+ this._removeInverse(id, previousPayload, inversePayloadMap);
}
- idToPayloads[id] = relationshipData;
- this._populateInverse(relationshipData, inverseRelationshipData, inverseIdToPayloads, inverseIsMany);
+ payloadMap.set(modelName, id, relationshipData);
+ this._populateInverse(relationshipData, inverseRelationshipData, inversePayloadMap, inverseIsMany);
}
};
- RelationshipPayloads.prototype._populateInverse = function _populateInverse(relationshipData, inversePayload, inverseIdToPayloads, inverseIsMany) {
+ RelationshipPayloads.prototype._populateInverse = function _populateInverse(relationshipData, inversePayload, inversePayloadMap, inverseIsMany) {
if (!relationshipData.data) {
// This id doesn't have an inverse, eg a belongsTo with a payload
// { data: null }, so there's nothing to populate
return;
}
if (Array.isArray(relationshipData.data)) {
for (var i = 0; i < relationshipData.data.length; ++i) {
- var inverseId = relationshipData.data[i].id;
- this._addToInverse(inversePayload, inverseId, inverseIdToPayloads, inverseIsMany);
+ var resourceIdentifier = relationshipData.data[i];
+ this._addToInverse(inversePayload, resourceIdentifier, inversePayloadMap, inverseIsMany);
}
} else {
- var _inverseId = relationshipData.data.id;
- this._addToInverse(inversePayload, _inverseId, inverseIdToPayloads, inverseIsMany);
+ var _resourceIdentifier = relationshipData.data;
+ this._addToInverse(inversePayload, _resourceIdentifier, inversePayloadMap, inverseIsMany);
}
};
- RelationshipPayloads.prototype._addToInverse = function _addToInverse(inversePayload, inverseId, inverseIdToPayloads, inverseIsMany) {
- if (this._isReflexive && inversePayload.data.id === inverseId) {
+ RelationshipPayloads.prototype._addToInverse = function _addToInverse(inversePayload, resourceIdentifier, inversePayloadMap, inverseIsMany) {
+ var relInfo = this._relInfo;
+
+ if (relInfo.isReflexive && inversePayload.data.id === resourceIdentifier.id) {
// eg <user:1>.friends = [{ id: 1, type: 'user' }]
return;
}
- var existingPayload = inverseIdToPayloads[inverseId];
+ var existingPayload = inversePayloadMap.get(resourceIdentifier.type, resourceIdentifier.id);
var existingData = existingPayload && existingPayload.data;
if (existingData) {
// There already is an inverse, either add or overwrite depehnding on
// whether the inverse is a many relationship or not
//
if (Array.isArray(existingData)) {
existingData.push(inversePayload.data);
} else {
- inverseIdToPayloads[inverseId] = inversePayload;
+ inversePayloadMap.set(resourceIdentifier.type, resourceIdentifier.id, inversePayload);
}
} else {
// first time we're populating the inverse side
//
if (inverseIsMany) {
- inverseIdToPayloads[inverseId] = {
+ inversePayloadMap.set(resourceIdentifier.type, resourceIdentifier.id, {
data: [inversePayload.data]
- };
+ });
} else {
- inverseIdToPayloads[inverseId] = inversePayload;
+ inversePayloadMap.set(resourceIdentifier.type, resourceIdentifier.id, inversePayload);
}
}
};
- RelationshipPayloads.prototype._removeInverse = function _removeInverse(id, previousPayload, inverseIdToPayloads) {
+ RelationshipPayloads.prototype._removeInverse = function _removeInverse(id, previousPayload, inversePayloadMap) {
var data = previousPayload && previousPayload.data;
if (!data) {
// either this is the first time we've seen a payload for this id, or its
// previous payload indicated that it had no inverse, eg a belongsTo
// relationship with payload { data: null }
@@ -8432,19 +8576,20 @@
}
if (Array.isArray(data)) {
// TODO: diff rather than removeall addall?
for (var i = 0; i < data.length; ++i) {
- this._removeFromInverse(id, data[i].id, inverseIdToPayloads);
+ var resourceIdentifier = data[i];
+ this._removeFromInverse(id, resourceIdentifier, inversePayloadMap);
}
} else {
- this._removeFromInverse(id, data.id, inverseIdToPayloads);
+ this._removeFromInverse(id, data, inversePayloadMap);
}
};
- RelationshipPayloads.prototype._removeFromInverse = function _removeFromInverse(id, inverseId, inversePayloads) {
- var inversePayload = inversePayloads[inverseId];
+ RelationshipPayloads.prototype._removeFromInverse = function _removeFromInverse(id, resourceIdentifier, inversePayloads) {
+ var inversePayload = inversePayloads.get(resourceIdentifier.type, resourceIdentifier.id);
var data = inversePayload && inversePayload.data;
if (!data) {
return;
}
@@ -8452,25 +8597,27 @@
if (Array.isArray(data)) {
inversePayload.data = data.filter(function (x) {
return x.id !== id;
});
} else {
- inversePayloads[inverseId] = {
+ inversePayloads.set(resourceIdentifier.type, resourceIdentifier.id, {
data: null
- };
+ });
}
};
_createClass(RelationshipPayloads, [{
key: '_lhsRelationshipIsMany',
get: function () {
- return this._lhsRelationshipMeta && this._lhsRelationshipMeta.kind === 'hasMany';
+ var meta = this._relInfo.lhs_relationshipMeta;
+ return meta !== null && meta.kind === 'hasMany';
}
}, {
key: '_rhsRelationshipIsMany',
get: function () {
- return this._rhsRelationshipMeta && this._rhsRelationshipMeta.kind === 'hasMany';
+ var meta = this._relInfo.rhs_relationshipMeta;
+ return meta !== null && meta.kind === 'hasMany';
}
}]);
return RelationshipPayloads;
}();
@@ -18230,10 +18377,10 @@
});
define("ember-data/version", ["exports"], function (exports) {
"use strict";
exports.__esModule = true;
- exports.default = "2.16.1";
+ exports.default = "2.16.4";
});
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;