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 ;
@@ -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 [ IDENTIFIER_ARRAY_TAG ] . ref = null ;
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
- // Object.setPrototypeOf(IdentifierArray.prototype, Array.prototype);
587
+ //Object.setPrototypeOf(IdentifierArray.prototype, Array.prototype);
548
588
549
589
if ( DEPRECATE_ARRAY_LIKE ) {
550
590
IdentifierArray . prototype . DEPRECATED_CLASS_NAME = 'RecordArray' ;
0 commit comments