@ember-data/model 5.0.0-alpha.1 → 5.0.0-alpha.3

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-465843f4";
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-465843f4";
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 };
@@ -1 +1 @@
1
- {"version":3,"file":"-private.js","sources":["../src/-private/model-for-mixin.ts","../src/-private/diff-array.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","/**\n @module @ember-data/model\n*/\n\nexport interface ArrayDiffResult {\n firstChangeIndex: number | null;\n removedCount: number;\n addedCount: number;\n}\n\n/**\n @method diffArray\n @internal\n @param {Array} oldArray the old array\n @param {Array} newArray the new array\n @return {hash} {\n firstChangeIndex: <integer>, // null if no change\n addedCount: <integer>, // 0 if no change\n removedCount: <integer> // 0 if no change\n }\n*/\nexport default function diffArray(oldArray: unknown[], newArray: unknown[]): ArrayDiffResult {\n const oldLength = oldArray.length;\n const newLength = newArray.length;\n\n const shortestLength = Math.min(oldLength, newLength);\n let firstChangeIndex: number | null = null; // null signifies no changes\n\n // find the first change\n for (let i = 0; i < shortestLength; i++) {\n // compare each item in the array\n if (oldArray[i] !== newArray[i]) {\n firstChangeIndex = i;\n break;\n }\n }\n\n if (firstChangeIndex === null && newLength !== oldLength) {\n // no change found in the overlapping block\n // and array lengths differ,\n // so change starts at end of overlap\n firstChangeIndex = shortestLength;\n }\n\n let addedCount = 0;\n let removedCount = 0;\n if (firstChangeIndex !== null) {\n // we found a change, find the end of the change\n let unchangedEndBlockLength = shortestLength - firstChangeIndex;\n // walk back from the end of both arrays until we find a change\n for (let i = 1; i <= shortestLength; i++) {\n // compare each item in the array\n if (oldArray[oldLength - i] !== newArray[newLength - i]) {\n unchangedEndBlockLength = i - 1;\n break;\n }\n }\n addedCount = newLength - unchangedEndBlockLength - firstChangeIndex;\n removedCount = oldLength - unchangedEndBlockLength - firstChangeIndex;\n }\n\n return {\n firstChangeIndex,\n addedCount,\n removedCount,\n };\n}\n"],"names":["modelForMixin","store","normalizedModelName","owner","getOwner","MaybeMixin","factoryFor","mixin","class","ModelForMixin","Model","extend","__isMixin","__mixin","register","diffArray","oldArray","newArray","oldLength","length","newLength","shortestLength","Math","min","firstChangeIndex","i","addedCount","removedCount","unchangedEndBlockLength"],"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,CAA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KAAK,IAAI,IAAIJ,SAAS,KAAKF,SAAS,EAAE;AACxD;AACA;AACA;AACAM,IAAAA,gBAAgB,GAAGH,cAAc,CAAA;AACnC,GAAA;EAEA,IAAIK,UAAU,GAAG,CAAC,CAAA;EAClB,IAAIC,YAAY,GAAG,CAAC,CAAA;EACpB,IAAIH,gBAAgB,KAAK,IAAI,EAAE;AAC7B;AACA,IAAA,IAAII,uBAAuB,GAAGP,cAAc,GAAGG,gBAAgB,CAAA;AAC/D;IACA,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,IAAIJ,cAAc,EAAEI,CAAC,EAAE,EAAE;AACxC;AACA,MAAA,IAAIT,QAAQ,CAACE,SAAS,GAAGO,CAAC,CAAC,KAAKR,QAAQ,CAACG,SAAS,GAAGK,CAAC,CAAC,EAAE;QACvDG,uBAAuB,GAAGH,CAAC,GAAG,CAAC,CAAA;AAC/B,QAAA,MAAA;AACF,OAAA;AACF,KAAA;AACAC,IAAAA,UAAU,GAAGN,SAAS,GAAGQ,uBAAuB,GAAGJ,gBAAgB,CAAA;AACnEG,IAAAA,YAAY,GAAGT,SAAS,GAAGU,uBAAuB,GAAGJ,gBAAgB,CAAA;AACvE,GAAA;EAEA,OAAO;IACLA,gBAAgB;IAChBE,UAAU;AACVC,IAAAA,YAAAA;GACD,CAAA;AACH;;;;"}
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;;;;"}