@ember-data/model 4.11.0 → 4.12.0-alpha.0
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/diff-array.ts → -private.js} +41 -13
- package/addon/-private.js.map +1 -0
- package/addon/has-many-a275fe0d.js +6283 -0
- package/addon/has-many-a275fe0d.js.map +1 -0
- package/addon/index.js +1 -0
- package/addon/index.js.map +1 -0
- package/addon-main.js +90 -0
- package/package.json +43 -15
- package/addon/-private/attr.js +0 -162
- package/addon/-private/belongs-to.js +0 -268
- package/addon/-private/debug/assert-polymorphic-type.js +0 -71
- package/addon/-private/deprecated-promise-proxy.ts +0 -76
- package/addon/-private/errors.ts +0 -425
- package/addon/-private/has-many.js +0 -280
- package/addon/-private/index.ts +0 -14
- package/addon/-private/legacy-data-fetch.js +0 -395
- package/addon/-private/legacy-data-utils.ts +0 -92
- package/addon/-private/legacy-relationships-support.ts +0 -774
- package/addon/-private/many-array.ts +0 -401
- package/addon/-private/model-for-mixin.ts +0 -38
- package/addon/-private/model.js +0 -2516
- package/addon/-private/notify-changes.ts +0 -72
- package/addon/-private/promise-belongs-to.ts +0 -73
- package/addon/-private/promise-many-array.ts +0 -425
- package/addon/-private/promise-proxy-base.js +0 -4
- package/addon/-private/record-state.ts +0 -468
- package/addon/-private/references/belongs-to.ts +0 -624
- package/addon/-private/references/has-many.ts +0 -669
- package/addon/-private/relationship-meta.ts +0 -98
- package/addon/-private/util.ts +0 -31
- package/addon/index.ts +0 -39
- package/blueprints/model/HELP.md +0 -26
- package/blueprints/model/files/__root__/__path__/__name__.js +0 -5
- package/blueprints/model/index.js +0 -158
- package/blueprints/model/native-files/__root__/__path__/__name__.js +0 -5
- package/blueprints/model-test/index.js +0 -33
- package/blueprints/model-test/mocha-files/__root__/__path__/__test__.js +0 -18
- package/blueprints/model-test/mocha-rfc-232-files/__root__/__path__/__test__.js +0 -15
- package/blueprints/model-test/qunit-files/__root__/__path__/__test__.js +0 -14
- package/index.js +0 -46
|
@@ -1,13 +1,44 @@
|
|
|
1
|
+
import { M as Model } from "./has-many-a275fe0d";
|
|
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-a275fe0d";
|
|
3
|
+
import { getOwner } from '@ember/application';
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
In case someone defined a relationship to a mixin, for example:
|
|
7
|
+
```
|
|
8
|
+
import Model, { belongsTo, hasMany } from '@ember-data/model';
|
|
9
|
+
import Mixin from '@ember/object/mixin';
|
|
10
|
+
|
|
11
|
+
class CommentModel extends Model {
|
|
12
|
+
@belongsTo('commentable', { polymorphic: true }) owner;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
let Commentable = Mixin.create({
|
|
16
|
+
@hasMany('comment') comments;
|
|
17
|
+
});
|
|
18
|
+
```
|
|
19
|
+
we want to look up a Commentable class which has all the necessary
|
|
20
|
+
relationship meta data. Thus, we look up the mixin and create a mock
|
|
21
|
+
Model, so we can access the relationship CPs of the mixin (`comments`)
|
|
22
|
+
in this case
|
|
23
|
+
*/
|
|
24
|
+
function modelForMixin(store, normalizedModelName) {
|
|
25
|
+
let owner = getOwner(store);
|
|
26
|
+
let MaybeMixin = owner.factoryFor(`mixin:${normalizedModelName}`);
|
|
27
|
+
let mixin = MaybeMixin && MaybeMixin.class;
|
|
28
|
+
if (mixin) {
|
|
29
|
+
let ModelForMixin = Model.extend(mixin);
|
|
30
|
+
ModelForMixin.__isMixin = true;
|
|
31
|
+
ModelForMixin.__mixin = mixin;
|
|
32
|
+
//Cache the class as a model
|
|
33
|
+
owner.register('model:' + normalizedModelName, ModelForMixin);
|
|
34
|
+
}
|
|
35
|
+
return owner.factoryFor(`model:${normalizedModelName}`);
|
|
36
|
+
}
|
|
37
|
+
|
|
1
38
|
/**
|
|
2
39
|
@module @ember-data/model
|
|
3
40
|
*/
|
|
4
41
|
|
|
5
|
-
export interface ArrayDiffResult {
|
|
6
|
-
firstChangeIndex: number | null;
|
|
7
|
-
removedCount: number;
|
|
8
|
-
addedCount: number;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
42
|
/**
|
|
12
43
|
@method diffArray
|
|
13
44
|
@internal
|
|
@@ -19,12 +50,11 @@ export interface ArrayDiffResult {
|
|
|
19
50
|
removedCount: <integer> // 0 if no change
|
|
20
51
|
}
|
|
21
52
|
*/
|
|
22
|
-
|
|
53
|
+
function diffArray(oldArray, newArray) {
|
|
23
54
|
const oldLength = oldArray.length;
|
|
24
55
|
const newLength = newArray.length;
|
|
25
|
-
|
|
26
56
|
const shortestLength = Math.min(oldLength, newLength);
|
|
27
|
-
let firstChangeIndex
|
|
57
|
+
let firstChangeIndex = null; // null signifies no changes
|
|
28
58
|
|
|
29
59
|
// find the first change
|
|
30
60
|
for (let i = 0; i < shortestLength; i++) {
|
|
@@ -34,14 +64,12 @@ export default function diffArray(oldArray: unknown[], newArray: unknown[]): Arr
|
|
|
34
64
|
break;
|
|
35
65
|
}
|
|
36
66
|
}
|
|
37
|
-
|
|
38
67
|
if (firstChangeIndex === null && newLength !== oldLength) {
|
|
39
68
|
// no change found in the overlapping block
|
|
40
69
|
// and array lengths differ,
|
|
41
70
|
// so change starts at end of overlap
|
|
42
71
|
firstChangeIndex = shortestLength;
|
|
43
72
|
}
|
|
44
|
-
|
|
45
73
|
let addedCount = 0;
|
|
46
74
|
let removedCount = 0;
|
|
47
75
|
if (firstChangeIndex !== null) {
|
|
@@ -58,10 +86,10 @@ export default function diffArray(oldArray: unknown[], newArray: unknown[]): Arr
|
|
|
58
86
|
addedCount = newLength - unchangedEndBlockLength - firstChangeIndex;
|
|
59
87
|
removedCount = oldLength - unchangedEndBlockLength - firstChangeIndex;
|
|
60
88
|
}
|
|
61
|
-
|
|
62
89
|
return {
|
|
63
90
|
firstChangeIndex,
|
|
64
91
|
addedCount,
|
|
65
|
-
removedCount
|
|
92
|
+
removedCount
|
|
66
93
|
};
|
|
67
94
|
}
|
|
95
|
+
export { Model, modelForMixin as _modelForMixin, diffArray };
|
|
@@ -0,0 +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,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,S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