Skip to content
This repository was archived by the owner on Sep 17, 2023. It is now read-only.

Commit 44c2a49

Browse files
committed
Make MultiContextKey value a read-only array
1 parent 3989606 commit 44c2a49

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/simple-context-key.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,42 +129,44 @@ export class SingleContextKey<Value>
129129
/**
130130
* Multiple context value reference.
131131
*
132+
* Represents context value as read-only array of source values.
133+
*
132134
* @typeparam Src Value source type and context value item type.
133135
*/
134-
export type MultiContextRef<Src, Seed = unknown> = ContextRef<Src[], Src, Seed>;
136+
export type MultiContextRef<Src, Seed = unknown> = ContextRef<readonly Src[], Src, Seed>;
135137

136138
/**
137139
* Multiple context values key.
138140
*
139-
* Represents context value as array of source values.
141+
* Represents context value as read-only array of source values.
140142
*
141143
* Associated with empty array by default.
142144
*
143145
* @typeparam Src Value source type and context value item type.
144146
*/
145147
export class MultiContextKey<Src>
146-
extends SimpleContextKey<Src[], Src>
148+
extends SimpleContextKey<readonly Src[], Src>
147149
implements MultiContextRef<Src, AIterable<Src>> {
148150

149151
/**
150152
* A provider of context value used when there is no value associated with this key.
151153
*/
152-
readonly byDefault: ContextValueProvider<ContextValues, Src[]>;
154+
readonly byDefault: ContextValueProvider<ContextValues, readonly Src[]>;
153155

154156
/**
155157
* Constructs multiple context values key.
156158
*
157159
* @param name Human-readable key name.
158160
* @param byDefault Optional default value provider. If unspecified then the default value is empty array.
159161
*/
160-
constructor(name: string, byDefault: ContextValueProvider<ContextValues, Src[]> = valuesProvider()) {
162+
constructor(name: string, byDefault: ContextValueProvider<ContextValues, readonly Src[]> = valuesProvider()) {
161163
super(name);
162164
this.byDefault = byDefault;
163165
}
164166

165167
grow<Ctx extends ContextValues>(
166-
opts: ContextValueOpts<Ctx, Src[], Src, AIterable<Src>>,
167-
): Src[] | null | undefined {
168+
opts: ContextValueOpts<Ctx, readonly Src[], Src, AIterable<Src>>,
169+
): readonly Src[] | null | undefined {
168170

169171
const result = [...opts.seed];
170172

0 commit comments

Comments
 (0)