@ember-data/model 4.10.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,72 +0,0 @@
|
|
|
1
|
-
import { cacheFor } from '@ember/object/internals';
|
|
2
|
-
|
|
3
|
-
import type Store from '@ember-data/store';
|
|
4
|
-
import type { NotificationType } from '@ember-data/store/-private/managers/record-notification-manager';
|
|
5
|
-
import type { StableRecordIdentifier } from '@ember-data/types/q/identifier';
|
|
6
|
-
|
|
7
|
-
import type Model from './model';
|
|
8
|
-
import { LEGACY_SUPPORT } from './model';
|
|
9
|
-
|
|
10
|
-
export default function notifyChanges(
|
|
11
|
-
identifier: StableRecordIdentifier,
|
|
12
|
-
value: NotificationType,
|
|
13
|
-
key: string | undefined,
|
|
14
|
-
record: Model,
|
|
15
|
-
store: Store
|
|
16
|
-
) {
|
|
17
|
-
if (value === 'attributes') {
|
|
18
|
-
if (key) {
|
|
19
|
-
notifyAttribute(store, identifier, key, record);
|
|
20
|
-
} else {
|
|
21
|
-
record.eachAttribute((key) => {
|
|
22
|
-
notifyAttribute(store, identifier, key, record);
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
} else if (value === 'relationships') {
|
|
26
|
-
if (key) {
|
|
27
|
-
let meta = record.constructor.relationshipsByName.get(key);
|
|
28
|
-
notifyRelationship(identifier, key, record, meta);
|
|
29
|
-
} else {
|
|
30
|
-
record.eachRelationship((key, meta) => {
|
|
31
|
-
notifyRelationship(identifier, key, record, meta);
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
} else if (value === 'identity') {
|
|
35
|
-
record.notifyPropertyChange('id');
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function notifyRelationship(identifier: StableRecordIdentifier, key: string, record: Model, meta) {
|
|
40
|
-
if (meta.kind === 'belongsTo') {
|
|
41
|
-
record.notifyPropertyChange(key);
|
|
42
|
-
} else if (meta.kind === 'hasMany') {
|
|
43
|
-
let support = LEGACY_SUPPORT.get(identifier);
|
|
44
|
-
let manyArray = support && support._manyArrayCache[key];
|
|
45
|
-
let hasPromise = support && support._relationshipPromisesCache[key];
|
|
46
|
-
|
|
47
|
-
if (manyArray && hasPromise) {
|
|
48
|
-
// do nothing, we will notify the ManyArray directly
|
|
49
|
-
// once the fetch has completed.
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (manyArray) {
|
|
54
|
-
manyArray.notify();
|
|
55
|
-
|
|
56
|
-
//We need to notifyPropertyChange in the adding case because we need to make sure
|
|
57
|
-
//we fetch the newly added record in case it is unloaded
|
|
58
|
-
//TODO(Igor): Consider whether we could do this only if the record state is unloaded
|
|
59
|
-
if (!meta.options || meta.options.async || meta.options.async === undefined) {
|
|
60
|
-
record.notifyPropertyChange(key);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function notifyAttribute(store: Store, identifier: StableRecordIdentifier, key: string, record: Model) {
|
|
67
|
-
let currentValue = cacheFor(record, key);
|
|
68
|
-
|
|
69
|
-
if (currentValue !== store._instanceCache.getRecordData(identifier).getAttr(identifier, key)) {
|
|
70
|
-
record.notifyPropertyChange(key);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { assert } from '@ember/debug';
|
|
2
|
-
import { computed } from '@ember/object';
|
|
3
|
-
import type PromiseProxyMixin from '@ember/object/promise-proxy-mixin';
|
|
4
|
-
import type ObjectProxy from '@ember/object/proxy';
|
|
5
|
-
|
|
6
|
-
import type Store from '@ember-data/store';
|
|
7
|
-
import type { RecordInstance } from '@ember-data/types/q/record-instance';
|
|
8
|
-
import type { Dict } from '@ember-data/types/q/utils';
|
|
9
|
-
|
|
10
|
-
import { LegacySupport } from './legacy-relationships-support';
|
|
11
|
-
import { PromiseObject } from './promise-proxy-base';
|
|
12
|
-
|
|
13
|
-
export interface BelongsToProxyMeta {
|
|
14
|
-
key: string;
|
|
15
|
-
store: Store;
|
|
16
|
-
legacySupport: LegacySupport;
|
|
17
|
-
modelName: string;
|
|
18
|
-
}
|
|
19
|
-
export interface BelongsToProxyCreateArgs {
|
|
20
|
-
promise: Promise<RecordInstance | null>;
|
|
21
|
-
content?: RecordInstance | null;
|
|
22
|
-
_belongsToState: BelongsToProxyMeta;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
interface PromiseObjectType<T extends object> extends PromiseProxyMixin<T | null>, ObjectProxy<T> {
|
|
26
|
-
new <T extends object>(...args: unknown[]): PromiseObjectType<T>;
|
|
27
|
-
}
|
|
28
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
29
|
-
declare class PromiseObjectType<T extends object> {}
|
|
30
|
-
|
|
31
|
-
const Extended: PromiseObjectType<RecordInstance> = PromiseObject as unknown as PromiseObjectType<RecordInstance>;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
@module @ember-data/model
|
|
35
|
-
*/
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
A PromiseBelongsTo is a PromiseObject that also proxies certain method calls
|
|
39
|
-
to the underlying belongsTo model.
|
|
40
|
-
Right now we proxy:
|
|
41
|
-
* `reload()`
|
|
42
|
-
@class PromiseBelongsTo
|
|
43
|
-
@extends PromiseObject
|
|
44
|
-
@private
|
|
45
|
-
*/
|
|
46
|
-
class PromiseBelongsTo extends Extended<RecordInstance> {
|
|
47
|
-
declare _belongsToState: BelongsToProxyMeta;
|
|
48
|
-
// we don't proxy meta because we would need to proxy it to the relationship state container
|
|
49
|
-
// however, meta on relationships does not trigger change notifications.
|
|
50
|
-
// if you need relationship meta, you should do `record.belongsTo(relationshipName).meta()`
|
|
51
|
-
@computed()
|
|
52
|
-
get meta() {
|
|
53
|
-
// eslint-disable-next-line no-constant-condition
|
|
54
|
-
if (1) {
|
|
55
|
-
assert(
|
|
56
|
-
'You attempted to access meta on the promise for the async belongsTo relationship ' +
|
|
57
|
-
`${this.get('_belongsToState').modelName}:${this.get('_belongsToState').key}'.` +
|
|
58
|
-
'\nUse `record.belongsTo(relationshipName).meta()` instead.',
|
|
59
|
-
false
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
async reload(options: Dict<unknown>): Promise<this> {
|
|
66
|
-
assert('You are trying to reload an async belongsTo before it has been created', this.content !== undefined);
|
|
67
|
-
let { key, legacySupport } = this._belongsToState;
|
|
68
|
-
await legacySupport.reloadBelongsTo(key, options);
|
|
69
|
-
return this;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export default PromiseBelongsTo;
|
|
@@ -1,425 +0,0 @@
|
|
|
1
|
-
import ArrayMixin, { NativeArray } from '@ember/array';
|
|
2
|
-
import type ArrayProxy from '@ember/array/proxy';
|
|
3
|
-
import { assert, deprecate } from '@ember/debug';
|
|
4
|
-
import { dependentKeyCompat } from '@ember/object/compat';
|
|
5
|
-
import { DEBUG } from '@glimmer/env';
|
|
6
|
-
import { tracked } from '@glimmer/tracking';
|
|
7
|
-
import Ember from 'ember';
|
|
8
|
-
|
|
9
|
-
import { resolve } from 'rsvp';
|
|
10
|
-
|
|
11
|
-
import {
|
|
12
|
-
DEPRECATE_A_USAGE,
|
|
13
|
-
DEPRECATE_COMPUTED_CHAINS,
|
|
14
|
-
DEPRECATE_PROMISE_MANY_ARRAY_BEHAVIORS,
|
|
15
|
-
} from '@ember-data/private-build-infra/deprecations';
|
|
16
|
-
import { StableRecordIdentifier } from '@ember-data/types/q/identifier';
|
|
17
|
-
import type { RecordInstance } from '@ember-data/types/q/record-instance';
|
|
18
|
-
import { FindOptions } from '@ember-data/types/q/store';
|
|
19
|
-
|
|
20
|
-
import type ManyArray from './many-array';
|
|
21
|
-
|
|
22
|
-
export interface HasManyProxyCreateArgs {
|
|
23
|
-
promise: Promise<ManyArray>;
|
|
24
|
-
content?: ManyArray;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
@module @ember-data/model
|
|
29
|
-
*/
|
|
30
|
-
/**
|
|
31
|
-
This class is returned as the result of accessing an async hasMany relationship
|
|
32
|
-
on an instance of a Model extending from `@ember-data/model`.
|
|
33
|
-
|
|
34
|
-
A PromiseManyArray is an iterable proxy that allows templates to consume related
|
|
35
|
-
ManyArrays and update once their contents are no longer pending.
|
|
36
|
-
|
|
37
|
-
In your JS code you should resolve the promise first.
|
|
38
|
-
|
|
39
|
-
```js
|
|
40
|
-
const comments = await post.comments;
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
@class PromiseManyArray
|
|
44
|
-
@public
|
|
45
|
-
*/
|
|
46
|
-
export default interface PromiseManyArray extends Omit<ArrayProxy<StableRecordIdentifier, RecordInstance>, 'destroy'> {
|
|
47
|
-
createRecord(): RecordInstance;
|
|
48
|
-
reload(options: FindOptions): PromiseManyArray;
|
|
49
|
-
}
|
|
50
|
-
export default class PromiseManyArray {
|
|
51
|
-
declare promise: Promise<ManyArray> | null;
|
|
52
|
-
declare isDestroyed: boolean;
|
|
53
|
-
// @deprecated (isDestroyed is not deprecated)
|
|
54
|
-
declare isDestroying: boolean;
|
|
55
|
-
|
|
56
|
-
constructor(promise: Promise<ManyArray>, content?: ManyArray) {
|
|
57
|
-
this._update(promise, content);
|
|
58
|
-
this.isDestroyed = false;
|
|
59
|
-
this.isDestroying = false;
|
|
60
|
-
|
|
61
|
-
if (DEPRECATE_A_USAGE) {
|
|
62
|
-
const meta = Ember.meta(this);
|
|
63
|
-
meta.hasMixin = (mixin: Object) => {
|
|
64
|
-
deprecate(`Do not use A() on an EmberData PromiseManyArray`, false, {
|
|
65
|
-
id: 'ember-data:no-a-with-array-like',
|
|
66
|
-
until: '5.0',
|
|
67
|
-
since: { enabled: '4.7', available: '4.7' },
|
|
68
|
-
for: 'ember-data',
|
|
69
|
-
});
|
|
70
|
-
// @ts-expect-error ArrayMixin is more than a type
|
|
71
|
-
if (mixin === NativeArray || mixin === ArrayMixin) {
|
|
72
|
-
return true;
|
|
73
|
-
}
|
|
74
|
-
return false;
|
|
75
|
-
};
|
|
76
|
-
} else if (DEBUG) {
|
|
77
|
-
const meta = Ember.meta(this);
|
|
78
|
-
meta.hasMixin = (mixin: Object) => {
|
|
79
|
-
assert(`Do not use A() on an EmberData PromiseManyArray`);
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
//---- Methods/Properties on ArrayProxy that we will keep as our API
|
|
85
|
-
|
|
86
|
-
@tracked content: any | null = null;
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Retrieve the length of the content
|
|
90
|
-
* @property length
|
|
91
|
-
* @public
|
|
92
|
-
*/
|
|
93
|
-
@dependentKeyCompat
|
|
94
|
-
get length(): number {
|
|
95
|
-
// shouldn't be needed, but ends up being needed
|
|
96
|
-
// for computed chains even in 4.x
|
|
97
|
-
if (DEPRECATE_COMPUTED_CHAINS) {
|
|
98
|
-
this['[]'];
|
|
99
|
-
}
|
|
100
|
-
return this.content ? this.content.length : 0;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// ember-source < 3.23 (e.g. 3.20 lts)
|
|
104
|
-
// requires that the tag `'[]'` be notified
|
|
105
|
-
// on the ArrayProxy in order for `{{#each}}`
|
|
106
|
-
// to recompute. We entangle the '[]' tag from
|
|
107
|
-
@dependentKeyCompat
|
|
108
|
-
get '[]'() {
|
|
109
|
-
if (DEPRECATE_COMPUTED_CHAINS) {
|
|
110
|
-
return this.content?.length && this.content;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Iterate the proxied content. Called by the glimmer iterator in #each
|
|
116
|
-
* We do not guarantee that forEach will always be available. This
|
|
117
|
-
* may eventually be made to use Symbol.Iterator once glimmer supports it.
|
|
118
|
-
*
|
|
119
|
-
* @method forEach
|
|
120
|
-
* @param cb
|
|
121
|
-
* @returns
|
|
122
|
-
* @private
|
|
123
|
-
*/
|
|
124
|
-
forEach(cb) {
|
|
125
|
-
if (this.content && this.length) {
|
|
126
|
-
this.content.forEach(cb);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Reload the relationship
|
|
132
|
-
* @method reload
|
|
133
|
-
* @public
|
|
134
|
-
* @param options
|
|
135
|
-
* @returns
|
|
136
|
-
*/
|
|
137
|
-
reload(options: FindOptions) {
|
|
138
|
-
assert('You are trying to reload an async manyArray before it has been created', this.content);
|
|
139
|
-
this.content.reload(options);
|
|
140
|
-
return this;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
//---- Properties/Methods from the PromiseProxyMixin that we will keep as our API
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Whether the loading promise is still pending
|
|
147
|
-
*
|
|
148
|
-
* @property {boolean} isPending
|
|
149
|
-
* @public
|
|
150
|
-
*/
|
|
151
|
-
@tracked isPending: boolean = false;
|
|
152
|
-
/**
|
|
153
|
-
* Whether the loading promise rejected
|
|
154
|
-
*
|
|
155
|
-
* @property {boolean} isRejected
|
|
156
|
-
* @public
|
|
157
|
-
*/
|
|
158
|
-
@tracked isRejected: boolean = false;
|
|
159
|
-
/**
|
|
160
|
-
* Whether the loading promise succeeded
|
|
161
|
-
*
|
|
162
|
-
* @property {boolean} isFulfilled
|
|
163
|
-
* @public
|
|
164
|
-
*/
|
|
165
|
-
@tracked isFulfilled: boolean = false;
|
|
166
|
-
/**
|
|
167
|
-
* Whether the loading promise completed (resolved or rejected)
|
|
168
|
-
*
|
|
169
|
-
* @property {boolean} isSettled
|
|
170
|
-
* @public
|
|
171
|
-
*/
|
|
172
|
-
@tracked isSettled: boolean = false;
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* chain this promise
|
|
176
|
-
*
|
|
177
|
-
* @method then
|
|
178
|
-
* @public
|
|
179
|
-
* @param success
|
|
180
|
-
* @param fail
|
|
181
|
-
* @returns Promise
|
|
182
|
-
*/
|
|
183
|
-
then(s, f) {
|
|
184
|
-
return this.promise!.then(s, f);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* catch errors thrown by this promise
|
|
189
|
-
* @method catch
|
|
190
|
-
* @public
|
|
191
|
-
* @param callback
|
|
192
|
-
* @returns Promise
|
|
193
|
-
*/
|
|
194
|
-
catch(cb) {
|
|
195
|
-
return this.promise!.catch(cb);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* run cleanup after this promise completes
|
|
200
|
-
*
|
|
201
|
-
* @method finally
|
|
202
|
-
* @public
|
|
203
|
-
* @param callback
|
|
204
|
-
* @returns Promise
|
|
205
|
-
*/
|
|
206
|
-
finally(cb) {
|
|
207
|
-
return this.promise!.finally(cb);
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
//---- Methods on EmberObject that we should keep
|
|
211
|
-
|
|
212
|
-
destroy() {
|
|
213
|
-
this.isDestroying = true;
|
|
214
|
-
this.isDestroyed = true;
|
|
215
|
-
this.content = null;
|
|
216
|
-
this.promise = null;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
//---- Methods/Properties on ManyArray that we own and proxy to
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* Retrieve the links for this relationship
|
|
223
|
-
* @property links
|
|
224
|
-
* @public
|
|
225
|
-
*/
|
|
226
|
-
@dependentKeyCompat
|
|
227
|
-
get links() {
|
|
228
|
-
return this.content ? this.content.links : undefined;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
/**
|
|
232
|
-
* Retrieve the meta for this relationship
|
|
233
|
-
* @property meta
|
|
234
|
-
* @public
|
|
235
|
-
*/
|
|
236
|
-
@dependentKeyCompat
|
|
237
|
-
get meta() {
|
|
238
|
-
return this.content ? this.content.meta : undefined;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
//---- Our own stuff
|
|
242
|
-
|
|
243
|
-
_update(promise: Promise<ManyArray>, content?: ManyArray) {
|
|
244
|
-
if (content !== undefined) {
|
|
245
|
-
this.content = content;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
this.promise = tapPromise(this, promise);
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
static create({ promise, content }: HasManyProxyCreateArgs): PromiseManyArray {
|
|
252
|
-
return new this(promise, content);
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
if (DEPRECATE_PROMISE_MANY_ARRAY_BEHAVIORS) {
|
|
257
|
-
PromiseManyArray.prototype.createRecord = function createRecord(...args) {
|
|
258
|
-
deprecate(
|
|
259
|
-
`The createRecord method on ember-data's PromiseManyArray is deprecated. await the promise and work with the ManyArray directly.`,
|
|
260
|
-
false,
|
|
261
|
-
{
|
|
262
|
-
id: 'ember-data:deprecate-promise-many-array-behaviors',
|
|
263
|
-
until: '5.0',
|
|
264
|
-
since: { enabled: '4.7', available: '4.7' },
|
|
265
|
-
for: 'ember-data',
|
|
266
|
-
}
|
|
267
|
-
);
|
|
268
|
-
assert('You are trying to createRecord on an async manyArray before it has been created', this.content);
|
|
269
|
-
return this.content.createRecord(...args);
|
|
270
|
-
};
|
|
271
|
-
|
|
272
|
-
Object.defineProperty(PromiseManyArray.prototype, 'firstObject', {
|
|
273
|
-
get() {
|
|
274
|
-
deprecate(
|
|
275
|
-
`The firstObject property on ember-data's PromiseManyArray is deprecated. await the promise and work with the ManyArray directly.`,
|
|
276
|
-
false,
|
|
277
|
-
{
|
|
278
|
-
id: 'ember-data:deprecate-promise-many-array-behaviors',
|
|
279
|
-
until: '5.0',
|
|
280
|
-
since: { enabled: '4.7', available: '4.7' },
|
|
281
|
-
for: 'ember-data',
|
|
282
|
-
}
|
|
283
|
-
);
|
|
284
|
-
return this.content ? this.content.firstObject : undefined;
|
|
285
|
-
},
|
|
286
|
-
});
|
|
287
|
-
|
|
288
|
-
Object.defineProperty(PromiseManyArray.prototype, 'lastObject', {
|
|
289
|
-
get() {
|
|
290
|
-
deprecate(
|
|
291
|
-
`The lastObject property on ember-data's PromiseManyArray is deprecated. await the promise and work with the ManyArray directly.`,
|
|
292
|
-
false,
|
|
293
|
-
{
|
|
294
|
-
id: 'ember-data:deprecate-promise-many-array-behaviors',
|
|
295
|
-
until: '5.0',
|
|
296
|
-
since: { enabled: '4.7', available: '4.7' },
|
|
297
|
-
for: 'ember-data',
|
|
298
|
-
}
|
|
299
|
-
);
|
|
300
|
-
return this.content ? this.content.lastObject : undefined;
|
|
301
|
-
},
|
|
302
|
-
});
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
function tapPromise(proxy: PromiseManyArray, promise: Promise<ManyArray>) {
|
|
306
|
-
proxy.isPending = true;
|
|
307
|
-
proxy.isSettled = false;
|
|
308
|
-
proxy.isFulfilled = false;
|
|
309
|
-
proxy.isRejected = false;
|
|
310
|
-
return resolve(promise).then(
|
|
311
|
-
(content) => {
|
|
312
|
-
proxy.isPending = false;
|
|
313
|
-
proxy.isFulfilled = true;
|
|
314
|
-
proxy.isSettled = true;
|
|
315
|
-
proxy.content = content;
|
|
316
|
-
return content;
|
|
317
|
-
},
|
|
318
|
-
(error) => {
|
|
319
|
-
proxy.isPending = false;
|
|
320
|
-
proxy.isFulfilled = false;
|
|
321
|
-
proxy.isRejected = true;
|
|
322
|
-
proxy.isSettled = true;
|
|
323
|
-
throw error;
|
|
324
|
-
}
|
|
325
|
-
);
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
if (DEPRECATE_PROMISE_MANY_ARRAY_BEHAVIORS) {
|
|
329
|
-
const EmberObjectMethods = [
|
|
330
|
-
'addObserver',
|
|
331
|
-
'cacheFor',
|
|
332
|
-
'decrementProperty',
|
|
333
|
-
'get',
|
|
334
|
-
'getProperties',
|
|
335
|
-
'incrementProperty',
|
|
336
|
-
'notifyPropertyChange',
|
|
337
|
-
'removeObserver',
|
|
338
|
-
'set',
|
|
339
|
-
'setProperties',
|
|
340
|
-
'toggleProperty',
|
|
341
|
-
];
|
|
342
|
-
EmberObjectMethods.forEach((method) => {
|
|
343
|
-
PromiseManyArray.prototype[method] = function delegatedMethod(...args) {
|
|
344
|
-
deprecate(
|
|
345
|
-
`The ${method} method on ember-data's PromiseManyArray is deprecated. await the promise and work with the ManyArray directly.`,
|
|
346
|
-
false,
|
|
347
|
-
{
|
|
348
|
-
id: 'ember-data:deprecate-promise-many-array-behaviors',
|
|
349
|
-
until: '5.0',
|
|
350
|
-
since: { enabled: '4.7', available: '4.7' },
|
|
351
|
-
for: 'ember-data',
|
|
352
|
-
}
|
|
353
|
-
);
|
|
354
|
-
return Ember[method](this, ...args);
|
|
355
|
-
};
|
|
356
|
-
});
|
|
357
|
-
|
|
358
|
-
const InheritedProxyMethods = [
|
|
359
|
-
'addArrayObserver',
|
|
360
|
-
'addObject',
|
|
361
|
-
'addObjects',
|
|
362
|
-
'any',
|
|
363
|
-
'arrayContentDidChange',
|
|
364
|
-
'arrayContentWillChange',
|
|
365
|
-
'clear',
|
|
366
|
-
'compact',
|
|
367
|
-
'every',
|
|
368
|
-
'filter',
|
|
369
|
-
'filterBy',
|
|
370
|
-
'find',
|
|
371
|
-
'findBy',
|
|
372
|
-
'getEach',
|
|
373
|
-
'includes',
|
|
374
|
-
'indexOf',
|
|
375
|
-
'insertAt',
|
|
376
|
-
'invoke',
|
|
377
|
-
'isAny',
|
|
378
|
-
'isEvery',
|
|
379
|
-
'lastIndexOf',
|
|
380
|
-
'map',
|
|
381
|
-
'mapBy',
|
|
382
|
-
// TODO update RFC to note objectAt was deprecated (forEach was left for iteration)
|
|
383
|
-
'objectAt',
|
|
384
|
-
'objectsAt',
|
|
385
|
-
'popObject',
|
|
386
|
-
'pushObject',
|
|
387
|
-
'pushObjects',
|
|
388
|
-
'reduce',
|
|
389
|
-
'reject',
|
|
390
|
-
'rejectBy',
|
|
391
|
-
'removeArrayObserver',
|
|
392
|
-
'removeAt',
|
|
393
|
-
'removeObject',
|
|
394
|
-
'removeObjects',
|
|
395
|
-
'replace',
|
|
396
|
-
'reverseObjects',
|
|
397
|
-
'setEach',
|
|
398
|
-
'setObjects',
|
|
399
|
-
'shiftObject',
|
|
400
|
-
'slice',
|
|
401
|
-
'sortBy',
|
|
402
|
-
'toArray',
|
|
403
|
-
'uniq',
|
|
404
|
-
'uniqBy',
|
|
405
|
-
'unshiftObject',
|
|
406
|
-
'unshiftObjects',
|
|
407
|
-
'without',
|
|
408
|
-
];
|
|
409
|
-
InheritedProxyMethods.forEach((method) => {
|
|
410
|
-
PromiseManyArray.prototype[method] = function proxiedMethod(...args) {
|
|
411
|
-
deprecate(
|
|
412
|
-
`The ${method} method on ember-data's PromiseManyArray is deprecated. await the promise and work with the ManyArray directly.`,
|
|
413
|
-
false,
|
|
414
|
-
{
|
|
415
|
-
id: 'ember-data:deprecate-promise-many-array-behaviors',
|
|
416
|
-
until: '5.0',
|
|
417
|
-
since: { enabled: '4.7', available: '4.7' },
|
|
418
|
-
for: 'ember-data',
|
|
419
|
-
}
|
|
420
|
-
);
|
|
421
|
-
assert(`Cannot call ${method} before content is assigned.`, this.content);
|
|
422
|
-
return this.content[method](...args);
|
|
423
|
-
};
|
|
424
|
-
});
|
|
425
|
-
}
|