@ember-data/model 5.0.0-alpha.0 → 5.0.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/addon/-private.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { M as Model } from "./has-many-
|
|
2
|
-
export { E as Errors, L as LEGACY_SUPPORT, R as ManyArray, P as PromiseBelongsTo, c as PromiseManyArray, a as attr, b as belongsTo, h as hasMany } from "./has-many-
|
|
1
|
+
import { M as Model } from "./has-many-2eb0dc13";
|
|
2
|
+
export { E as Errors, L as LEGACY_SUPPORT, R as ManyArray, P as PromiseBelongsTo, c as PromiseManyArray, a as attr, b as belongsTo, h as hasMany } from "./has-many-2eb0dc13";
|
|
3
3
|
import { getOwner } from '@ember/application';
|
|
4
4
|
|
|
5
5
|
/*
|
|
@@ -34,62 +34,4 @@ function modelForMixin(store, normalizedModelName) {
|
|
|
34
34
|
}
|
|
35
35
|
return owner.factoryFor(`model:${normalizedModelName}`);
|
|
36
36
|
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
@module @ember-data/model
|
|
40
|
-
*/
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
@method diffArray
|
|
44
|
-
@internal
|
|
45
|
-
@param {Array} oldArray the old array
|
|
46
|
-
@param {Array} newArray the new array
|
|
47
|
-
@return {hash} {
|
|
48
|
-
firstChangeIndex: <integer>, // null if no change
|
|
49
|
-
addedCount: <integer>, // 0 if no change
|
|
50
|
-
removedCount: <integer> // 0 if no change
|
|
51
|
-
}
|
|
52
|
-
*/
|
|
53
|
-
function diffArray(oldArray, newArray) {
|
|
54
|
-
const oldLength = oldArray.length;
|
|
55
|
-
const newLength = newArray.length;
|
|
56
|
-
const shortestLength = Math.min(oldLength, newLength);
|
|
57
|
-
let firstChangeIndex = null; // null signifies no changes
|
|
58
|
-
|
|
59
|
-
// find the first change
|
|
60
|
-
for (let i = 0; i < shortestLength; i++) {
|
|
61
|
-
// compare each item in the array
|
|
62
|
-
if (oldArray[i] !== newArray[i]) {
|
|
63
|
-
firstChangeIndex = i;
|
|
64
|
-
break;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
if (firstChangeIndex === null && newLength !== oldLength) {
|
|
68
|
-
// no change found in the overlapping block
|
|
69
|
-
// and array lengths differ,
|
|
70
|
-
// so change starts at end of overlap
|
|
71
|
-
firstChangeIndex = shortestLength;
|
|
72
|
-
}
|
|
73
|
-
let addedCount = 0;
|
|
74
|
-
let removedCount = 0;
|
|
75
|
-
if (firstChangeIndex !== null) {
|
|
76
|
-
// we found a change, find the end of the change
|
|
77
|
-
let unchangedEndBlockLength = shortestLength - firstChangeIndex;
|
|
78
|
-
// walk back from the end of both arrays until we find a change
|
|
79
|
-
for (let i = 1; i <= shortestLength; i++) {
|
|
80
|
-
// compare each item in the array
|
|
81
|
-
if (oldArray[oldLength - i] !== newArray[newLength - i]) {
|
|
82
|
-
unchangedEndBlockLength = i - 1;
|
|
83
|
-
break;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
addedCount = newLength - unchangedEndBlockLength - firstChangeIndex;
|
|
87
|
-
removedCount = oldLength - unchangedEndBlockLength - firstChangeIndex;
|
|
88
|
-
}
|
|
89
|
-
return {
|
|
90
|
-
firstChangeIndex,
|
|
91
|
-
addedCount,
|
|
92
|
-
removedCount
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
export { Model, modelForMixin as _modelForMixin, diffArray };
|
|
37
|
+
export { Model, modelForMixin as _modelForMixin };
|
package/addon/-private.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"-private.js","sources":["../src/-private/model-for-mixin.ts"
|
|
1
|
+
{"version":3,"file":"-private.js","sources":["../src/-private/model-for-mixin.ts"],"sourcesContent":["import { getOwner } from '@ember/application';\n\nimport type Store from '@ember-data/store';\n\nimport Model from './model';\n\n/*\n In case someone defined a relationship to a mixin, for example:\n ```\n import Model, { belongsTo, hasMany } from '@ember-data/model';\n import Mixin from '@ember/object/mixin';\n\n class CommentModel extends Model {\n @belongsTo('commentable', { polymorphic: true }) owner;\n }\n\n let Commentable = Mixin.create({\n @hasMany('comment') comments;\n });\n ```\n we want to look up a Commentable class which has all the necessary\n relationship meta data. Thus, we look up the mixin and create a mock\n Model, so we can access the relationship CPs of the mixin (`comments`)\n in this case\n */\nexport default function modelForMixin(store: Store, normalizedModelName: string): Model | null {\n let owner: any = getOwner(store);\n let MaybeMixin = owner.factoryFor(`mixin:${normalizedModelName}`);\n let mixin = MaybeMixin && MaybeMixin.class;\n if (mixin) {\n let ModelForMixin = Model.extend(mixin);\n ModelForMixin.__isMixin = true;\n ModelForMixin.__mixin = mixin;\n //Cache the class as a model\n owner.register('model:' + normalizedModelName, ModelForMixin);\n }\n return owner.factoryFor(`model:${normalizedModelName}`);\n}\n"],"names":["modelForMixin","store","normalizedModelName","owner","getOwner","MaybeMixin","factoryFor","mixin","class","ModelForMixin","Model","extend","__isMixin","__mixin","register"],"mappings":";;;;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,aAAaA,CAACC,KAAY,EAAEC,mBAA2B,EAAgB;AAC7F,EAAA,IAAIC,KAAU,GAAGC,QAAQ,CAACH,KAAK,CAAC,CAAA;EAChC,IAAII,UAAU,GAAGF,KAAK,CAACG,UAAU,CAAE,CAAA,MAAA,EAAQJ,mBAAoB,CAAA,CAAC,CAAC,CAAA;AACjE,EAAA,IAAIK,KAAK,GAAGF,UAAU,IAAIA,UAAU,CAACG,KAAK,CAAA;AAC1C,EAAA,IAAID,KAAK,EAAE;AACT,IAAA,IAAIE,aAAa,GAAGC,KAAK,CAACC,MAAM,CAACJ,KAAK,CAAC,CAAA;IACvCE,aAAa,CAACG,SAAS,GAAG,IAAI,CAAA;IAC9BH,aAAa,CAACI,OAAO,GAAGN,KAAK,CAAA;AAC7B;IACAJ,KAAK,CAACW,QAAQ,CAAC,QAAQ,GAAGZ,mBAAmB,EAAEO,aAAa,CAAC,CAAA;AAC/D,GAAA;AACA,EAAA,OAAON,KAAK,CAACG,UAAU,CAAE,CAAQJ,MAAAA,EAAAA,mBAAoB,EAAC,CAAC,CAAA;AACzD;;;;"}
|