@ember-data/store 4.11.1 → 4.11.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/caches/instance-cache.ts +11 -1
- package/addon/-private/caches/record-data-for.ts +1 -1
- package/addon/-private/index.ts +2 -0
- package/addon/-private/managers/record-array-manager.ts +8 -5
- package/addon/-private/proxies/promise-proxies.ts +2 -2
- package/addon/-private/record-arrays/identifier-array.ts +47 -7
- package/package.json +6 -6
|
@@ -37,7 +37,7 @@ import { assertIdentifierHasId } from '../store-service';
|
|
|
37
37
|
import coerceId, { ensureStringId } from '../utils/coerce-id';
|
|
38
38
|
import constructResource from '../utils/construct-resource';
|
|
39
39
|
import normalizeModelName from '../utils/normalize-model-name';
|
|
40
|
-
import { removeRecordDataFor, setRecordDataFor } from './record-data-for';
|
|
40
|
+
import { RecordDataForIdentifierCache, removeRecordDataFor, setRecordDataFor } from './record-data-for';
|
|
41
41
|
|
|
42
42
|
let _peekGraph: peekGraph;
|
|
43
43
|
if (HAS_RECORD_DATA_PACKAGE) {
|
|
@@ -237,6 +237,10 @@ export class InstanceCache {
|
|
|
237
237
|
let record = this.__instances.record.get(identifier);
|
|
238
238
|
|
|
239
239
|
if (!record) {
|
|
240
|
+
assert(
|
|
241
|
+
`Cannot create a new record instance while the store is being destroyed`,
|
|
242
|
+
!this.store.isDestroying && !this.store.isDestroyed
|
|
243
|
+
);
|
|
240
244
|
const recordData = this.getRecordData(identifier);
|
|
241
245
|
|
|
242
246
|
record = this.store.instantiateRecord(
|
|
@@ -693,3 +697,9 @@ function _isLoading(cache: InstanceCache, identifier: StableRecordIdentifier): b
|
|
|
693
697
|
req.getPendingRequestsForRecord(identifier).some((req) => req.type === 'query')
|
|
694
698
|
);
|
|
695
699
|
}
|
|
700
|
+
|
|
701
|
+
export function _clearCaches() {
|
|
702
|
+
RecordCache.clear();
|
|
703
|
+
StoreMap.clear();
|
|
704
|
+
RecordDataForIdentifierCache.clear();
|
|
705
|
+
}
|
|
@@ -9,7 +9,7 @@ import type { RecordInstance } from '@ember-data/types/q/record-instance';
|
|
|
9
9
|
* Model or Identifier
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
const RecordDataForIdentifierCache = new Map<StableRecordIdentifier | RecordInstance, RecordData>();
|
|
12
|
+
export const RecordDataForIdentifierCache = new Map<StableRecordIdentifier | RecordInstance, RecordData>();
|
|
13
13
|
|
|
14
14
|
export function setRecordDataFor(identifier: StableRecordIdentifier | RecordInstance, recordData: RecordData): void {
|
|
15
15
|
assert(
|
package/addon/-private/index.ts
CHANGED
|
@@ -46,6 +46,7 @@ export {
|
|
|
46
46
|
default as RecordArray,
|
|
47
47
|
default as IdentifierArray,
|
|
48
48
|
Collection as AdapterPopulatedRecordArray,
|
|
49
|
+
notifyArray,
|
|
49
50
|
SOURCE,
|
|
50
51
|
MUTATE,
|
|
51
52
|
IDENTIFIER_ARRAY_TAG,
|
|
@@ -56,4 +57,5 @@ export { default as RecordArrayManager, fastPush } from './managers/record-array
|
|
|
56
57
|
export { default as SnapshotRecordArray } from './network/snapshot-record-array';
|
|
57
58
|
|
|
58
59
|
// leaked for private use / test use, should investigate removing
|
|
60
|
+
export { _clearCaches } from './caches/instance-cache';
|
|
59
61
|
export { default as recordDataFor, removeRecordDataFor } from './caches/record-data-for';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
@module @ember-data/store
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import { addTransactionCB } from '@ember-data/tracking/-private';
|
|
5
5
|
import type { CollectionResourceDocument } from '@ember-data/types/q/ember-data-json-api';
|
|
6
6
|
import type { StableRecordIdentifier } from '@ember-data/types/q/identifier';
|
|
7
7
|
import type { Dict } from '@ember-data/types/q/utils';
|
|
@@ -10,6 +10,8 @@ import IdentifierArray, {
|
|
|
10
10
|
Collection,
|
|
11
11
|
CollectionCreateOptions,
|
|
12
12
|
IDENTIFIER_ARRAY_TAG,
|
|
13
|
+
NOTIFY,
|
|
14
|
+
notifyArray,
|
|
13
15
|
SOURCE,
|
|
14
16
|
} from '../record-arrays/identifier-array';
|
|
15
17
|
import type Store from '../store-service';
|
|
@@ -175,9 +177,9 @@ class RecordArrayManager {
|
|
|
175
177
|
let tag = array[IDENTIFIER_ARRAY_TAG];
|
|
176
178
|
if (!tag.shouldReset) {
|
|
177
179
|
tag.shouldReset = true;
|
|
178
|
-
|
|
179
|
-
} else if (delta > 0 && tag.t) {
|
|
180
|
-
|
|
180
|
+
addTransactionCB(array[NOTIFY]);
|
|
181
|
+
} else if (delta > 0 && !tag.t) {
|
|
182
|
+
addTransactionCB(array[NOTIFY]);
|
|
181
183
|
}
|
|
182
184
|
}
|
|
183
185
|
|
|
@@ -244,7 +246,8 @@ class RecordArrayManager {
|
|
|
244
246
|
const old = source.slice();
|
|
245
247
|
source.length = 0;
|
|
246
248
|
fastPush(source, identifiers);
|
|
247
|
-
|
|
249
|
+
|
|
250
|
+
notifyArray(array);
|
|
248
251
|
array.meta = payload.meta || null;
|
|
249
252
|
array.links = payload.links || null;
|
|
250
253
|
array.isLoaded = true;
|
|
@@ -135,7 +135,7 @@ export function promiseArray<I, T extends EmberArrayLike<I>>(promise: Promise<T>
|
|
|
135
135
|
return Reflect.get(target, prop, receiver);
|
|
136
136
|
}
|
|
137
137
|
if (ALLOWABLE_PROPS.includes(prop)) {
|
|
138
|
-
return
|
|
138
|
+
return target[prop];
|
|
139
139
|
}
|
|
140
140
|
if (!ALLOWABLE_METHODS.includes(prop)) {
|
|
141
141
|
deprecate(
|
|
@@ -190,7 +190,7 @@ export function promiseObject<T>(promise: Promise<T>): PromiseObjectProxy<T> {
|
|
|
190
190
|
}
|
|
191
191
|
|
|
192
192
|
if (ALLOWABLE_PROPS.includes(prop)) {
|
|
193
|
-
return
|
|
193
|
+
return target[prop];
|
|
194
194
|
}
|
|
195
195
|
|
|
196
196
|
if (!ALLOWABLE_METHODS.includes(prop)) {
|
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
2
|
@module @ember-data/store
|
|
3
3
|
*/
|
|
4
|
+
// @ts-expect-error
|
|
5
|
+
import { tagForProperty } from '@ember/-internals/metal';
|
|
4
6
|
import { assert, deprecate } from '@ember/debug';
|
|
5
7
|
import { get, set } from '@ember/object';
|
|
6
8
|
import { dependentKeyCompat } from '@ember/object/compat';
|
|
7
9
|
import { compare } from '@ember/utils';
|
|
8
10
|
import { DEBUG } from '@glimmer/env';
|
|
9
11
|
import { tracked } from '@glimmer/tracking';
|
|
12
|
+
// @ts-expect-error
|
|
13
|
+
import { dirtyTag } from '@glimmer/validator';
|
|
10
14
|
import Ember from 'ember';
|
|
11
15
|
|
|
12
16
|
import {
|
|
13
17
|
DEPRECATE_A_USAGE,
|
|
14
18
|
DEPRECATE_ARRAY_LIKE,
|
|
19
|
+
DEPRECATE_COMPUTED_CHAINS,
|
|
15
20
|
DEPRECATE_PROMISE_PROXIES,
|
|
16
21
|
DEPRECATE_SNAPSHOT_MODEL_CLASS_ACCESS,
|
|
17
22
|
} from '@ember-data/private-build-infra/deprecations';
|
|
@@ -63,6 +68,18 @@ function isArraySetter(prop: KeyType): boolean {
|
|
|
63
68
|
export const IDENTIFIER_ARRAY_TAG = Symbol('#tag');
|
|
64
69
|
export const SOURCE = Symbol('#source');
|
|
65
70
|
export const MUTATE = Symbol('#update');
|
|
71
|
+
export const NOTIFY = Symbol('#notify');
|
|
72
|
+
|
|
73
|
+
export function notifyArray(arr: IdentifierArray) {
|
|
74
|
+
arr[IDENTIFIER_ARRAY_TAG].ref = null;
|
|
75
|
+
|
|
76
|
+
if (DEPRECATE_COMPUTED_CHAINS) {
|
|
77
|
+
// eslint-disable-next-line
|
|
78
|
+
dirtyTag(tagForProperty(arr, 'length'));
|
|
79
|
+
// eslint-disable-next-line
|
|
80
|
+
dirtyTag(tagForProperty(arr, '[]'));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
66
83
|
|
|
67
84
|
function convertToInt(prop: KeyType): number | null {
|
|
68
85
|
if (typeof prop === 'symbol') return null;
|
|
@@ -76,8 +93,16 @@ function convertToInt(prop: KeyType): number | null {
|
|
|
76
93
|
|
|
77
94
|
class Tag {
|
|
78
95
|
@tracked ref = null;
|
|
79
|
-
shouldReset: boolean
|
|
80
|
-
|
|
96
|
+
declare shouldReset: boolean;
|
|
97
|
+
/*
|
|
98
|
+
* whether this was part of a transaction when last mutated
|
|
99
|
+
*/
|
|
100
|
+
declare t: boolean;
|
|
101
|
+
|
|
102
|
+
constructor() {
|
|
103
|
+
this.shouldReset = false;
|
|
104
|
+
this.t = false;
|
|
105
|
+
}
|
|
81
106
|
}
|
|
82
107
|
|
|
83
108
|
type ProxiedMethod = (...args: unknown[]) => unknown;
|
|
@@ -127,11 +152,9 @@ interface PrivateState {
|
|
|
127
152
|
@class RecordArray
|
|
128
153
|
@public
|
|
129
154
|
*/
|
|
130
|
-
|
|
131
|
-
interface IdentifierArray {
|
|
155
|
+
interface IdentifierArray extends Omit<Array<RecordInstance>, '[]'> {
|
|
132
156
|
[MUTATE]?(prop: string, args: unknown[], result?: unknown): void;
|
|
133
157
|
}
|
|
134
|
-
interface IdentifierArray extends Array<RecordInstance> {}
|
|
135
158
|
class IdentifierArray {
|
|
136
159
|
declare DEPRECATED_CLASS_NAME: string;
|
|
137
160
|
/**
|
|
@@ -155,6 +178,9 @@ class IdentifierArray {
|
|
|
155
178
|
|
|
156
179
|
[IDENTIFIER_ARRAY_TAG] = new Tag();
|
|
157
180
|
[SOURCE]: StableRecordIdentifier[];
|
|
181
|
+
[NOTIFY]() {
|
|
182
|
+
notifyArray(this);
|
|
183
|
+
}
|
|
158
184
|
|
|
159
185
|
declare links: Links | PaginationLinks | null;
|
|
160
186
|
declare meta: Dict<unknown> | null;
|
|
@@ -183,7 +209,7 @@ class IdentifierArray {
|
|
|
183
209
|
// changing the reference breaks the Proxy
|
|
184
210
|
// this[SOURCE] = [];
|
|
185
211
|
this[SOURCE].length = 0;
|
|
186
|
-
this[
|
|
212
|
+
this[NOTIFY]();
|
|
187
213
|
this.isDestroyed = true;
|
|
188
214
|
}
|
|
189
215
|
|
|
@@ -196,6 +222,14 @@ class IdentifierArray {
|
|
|
196
222
|
this[SOURCE].length = value;
|
|
197
223
|
}
|
|
198
224
|
|
|
225
|
+
// here to support computed chains
|
|
226
|
+
// and {{#each}}
|
|
227
|
+
get '[]'() {
|
|
228
|
+
if (DEPRECATE_COMPUTED_CHAINS) {
|
|
229
|
+
return this;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
199
233
|
constructor(options: IdentifierArrayCreateOptions) {
|
|
200
234
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
201
235
|
let self = this;
|
|
@@ -296,6 +330,10 @@ class IdentifierArray {
|
|
|
296
330
|
}
|
|
297
331
|
}
|
|
298
332
|
|
|
333
|
+
if (prop === NOTIFY || prop === IDENTIFIER_ARRAY_TAG || prop === SOURCE) {
|
|
334
|
+
return self[prop];
|
|
335
|
+
}
|
|
336
|
+
|
|
299
337
|
let fn = boundFns.get(prop);
|
|
300
338
|
if (fn) return fn;
|
|
301
339
|
|
|
@@ -403,6 +441,8 @@ class IdentifierArray {
|
|
|
403
441
|
};
|
|
404
442
|
}
|
|
405
443
|
|
|
444
|
+
this[NOTIFY] = this[NOTIFY].bind(proxy);
|
|
445
|
+
|
|
406
446
|
return proxy;
|
|
407
447
|
}
|
|
408
448
|
|
|
@@ -544,7 +584,7 @@ export class Collection extends IdentifierArray {
|
|
|
544
584
|
Collection.prototype.query = null;
|
|
545
585
|
|
|
546
586
|
// Ensure instanceof works correctly
|
|
547
|
-
//
|
|
587
|
+
//Object.setPrototypeOf(IdentifierArray.prototype, Array.prototype);
|
|
548
588
|
|
|
549
589
|
if (DEPRECATE_ARRAY_LIKE) {
|
|
550
590
|
IdentifierArray.prototype.DEPRECATED_CLASS_NAME = 'RecordArray';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ember-data/store",
|
|
3
|
-
"version": "4.11.
|
|
3
|
+
"version": "4.11.3",
|
|
4
4
|
"description": "The core of EmberData. Provides the Store service which coordinates the cache with the network and presentation layers.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ember-addon"
|
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
"author": "",
|
|
15
15
|
"directories": {},
|
|
16
16
|
"peerDependencies": {
|
|
17
|
-
"@ember-data/model": "4.11.
|
|
18
|
-
"@ember-data/record-data": "4.11.
|
|
19
|
-
"@ember-data/tracking": "4.11.
|
|
17
|
+
"@ember-data/model": "4.11.3",
|
|
18
|
+
"@ember-data/record-data": "4.11.3",
|
|
19
|
+
"@ember-data/tracking": "4.11.3",
|
|
20
20
|
"@ember/string": "^3.0.1",
|
|
21
21
|
"@glimmer/tracking": "^1.1.2"
|
|
22
22
|
},
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
}
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@ember-data/canary-features": "4.11.
|
|
41
|
-
"@ember-data/private-build-infra": "4.11.
|
|
40
|
+
"@ember-data/canary-features": "4.11.3",
|
|
41
|
+
"@ember-data/private-build-infra": "4.11.3",
|
|
42
42
|
"@embroider/macros": "^1.10.0",
|
|
43
43
|
"ember-auto-import": "^2.4.3",
|
|
44
44
|
"ember-cached-decorator-polyfill": "^1.0.1",
|