@@ -144,6 +144,10 @@ type DependenciesMapInner<V> = (
144
144
)
145
145
) ;
146
146
147
+ /**
148
+ * A map that stores values indexed by an array of keys. If the keys are objects and the environment supports WeakRefs,
149
+ * they are stored in a WeakMap.
150
+ */
147
151
export class DependenciesMap < K extends any [ ] , V > {
148
152
private _inner : DependenciesMapInner < V > = { map : new MaybeWeakMap ( ) , hasValue : false , value : undefined } ;
149
153
@@ -190,6 +194,15 @@ export class DependenciesMap<K extends any[], V> {
190
194
}
191
195
}
192
196
197
+ private * _iterateInner ( dependencies : any [ ] , inner : DependenciesMapInner < V > ) : IterableIterator < [ K , V ] > {
198
+ if ( inner . hasValue ) {
199
+ yield [ dependencies as K , inner . value ] ;
200
+ }
201
+ for ( const [ key , value ] of inner . map ) {
202
+ yield * this . _iterateInner ( [ ...dependencies , key ] , value ) ;
203
+ }
204
+ }
205
+
193
206
get ( dependencies : K ) : V | undefined {
194
207
return Result . or ( this . _unwrapFromInner ( dependencies , this . _inner ) , undefined ) ;
195
208
}
@@ -211,5 +224,9 @@ export class DependenciesMap<K extends any[], V> {
211
224
this . _inner = { map : new MaybeWeakMap ( ) , hasValue : false , value : undefined } ;
212
225
}
213
226
227
+ * [ Symbol . iterator ] ( ) : IterableIterator < [ K , V ] > {
228
+ yield * this . _iterateInner ( [ ] , this . _inner ) ;
229
+ }
230
+
214
231
[ Symbol . toStringTag ] = "DependenciesMap" ;
215
232
}
0 commit comments