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 = false ;
80
- t = false ;
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 ;
@@ -154,11 +179,9 @@ function safeForEach(
154
179
@class RecordArray
155
180
@public
156
181
*/
157
-
158
- interface IdentifierArray {
182
+ interface IdentifierArray extends Omit < Array < RecordInstance > , '[]' > {
159
183
[ MUTATE ] ?( prop : string , args : unknown [ ] , result ?: unknown ) : void ;
160
184
}
161
- interface IdentifierArray extends Array < RecordInstance > { }
162
185
class IdentifierArray {
163
186
declare DEPRECATED_CLASS_NAME : string ;
164
187
/**
@@ -182,6 +205,9 @@ class IdentifierArray {
182
205
183
206
[ IDENTIFIER_ARRAY_TAG ] = new Tag ( ) ;
184
207
[ SOURCE ] : StableRecordIdentifier [ ] ;
208
+ [ NOTIFY ] ( ) {
209
+ notifyArray ( this ) ;
210
+ }
185
211
186
212
declare links : Links | PaginationLinks | null ;
187
213
declare meta : Dict < unknown > | null ;
@@ -210,7 +236,7 @@ class IdentifierArray {
210
236
// changing the reference breaks the Proxy
211
237
// this[SOURCE] = [];
212
238
this [ SOURCE ] . length = 0 ;
213
- this [ IDENTIFIER_ARRAY_TAG ] . ref = null ;
239
+ this [ NOTIFY ] ( ) ;
214
240
this . isDestroyed = true ;
215
241
}
216
242
@@ -223,6 +249,14 @@ class IdentifierArray {
223
249
this [ SOURCE ] . length = value ;
224
250
}
225
251
252
+ // here to support computed chains
253
+ // and {{#each}}
254
+ get '[]' ( ) {
255
+ if ( DEPRECATE_COMPUTED_CHAINS ) {
256
+ return this ;
257
+ }
258
+ }
259
+
226
260
constructor ( options : IdentifierArrayCreateOptions ) {
227
261
// eslint-disable-next-line @typescript-eslint/no-this-alias
228
262
let self = this ;
@@ -333,6 +367,10 @@ class IdentifierArray {
333
367
}
334
368
}
335
369
370
+ if ( prop === NOTIFY || prop === IDENTIFIER_ARRAY_TAG || prop === SOURCE ) {
371
+ return self [ prop ] ;
372
+ }
373
+
336
374
let fn = boundFns . get ( prop ) ;
337
375
if ( fn ) return fn ;
338
376
@@ -440,6 +478,8 @@ class IdentifierArray {
440
478
} ;
441
479
}
442
480
481
+ this [ NOTIFY ] = this [ NOTIFY ] . bind ( proxy ) ;
482
+
443
483
return proxy ;
444
484
}
445
485
@@ -581,7 +621,7 @@ export class Collection extends IdentifierArray {
581
621
Collection . prototype . query = null ;
582
622
583
623
// Ensure instanceof works correctly
584
- // Object.setPrototypeOf(IdentifierArray.prototype, Array.prototype);
624
+ //Object.setPrototypeOf(IdentifierArray.prototype, Array.prototype);
585
625
586
626
if ( DEPRECATE_ARRAY_LIKE ) {
587
627
IdentifierArray . prototype . DEPRECATED_CLASS_NAME = 'RecordArray' ;
0 commit comments