File tree 2 files changed +9
-4
lines changed
2 files changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -182,8 +182,10 @@ A new locale has started to load. The `detail` object also contains:
182
182
- ` loadingLocale: string ` : Code of the locale that has started loading.
183
183
184
184
A ` loading ` status can be followed by a ` ready ` , ` error ` , or ` loading ` status.
185
- It will be followed by another ` loading ` status in the case that a second locale
186
- was requested before the first one finished loading.
185
+
186
+ In the case that a second locale is requested before the first one finishes
187
+ loading, a new ` loading ` event is dispatched, and no ` ready ` or ` error ` event
188
+ will be dispatched for the first request, because it is now stale.
187
189
188
190
#### ` ready `
189
191
Original file line number Diff line number Diff line change @@ -172,6 +172,7 @@ let loadLocale: ((locale: string) => Promise<LocaleModule>) | undefined;
172
172
let configured = false ;
173
173
let templates : TemplateMap | undefined ;
174
174
let loading = new Deferred < void > ( ) ;
175
+ let requestId = 0 ;
175
176
176
177
/**
177
178
* Set configuration parameters for lit-localize when in runtime mode. Returns
@@ -254,6 +255,8 @@ const setLocale: ((newLocale: string) => void) & {
254
255
if ( ! validLocales . has ( newLocale ) ) {
255
256
throw new Error ( 'Invalid locale code' ) ;
256
257
}
258
+ requestId ++ ;
259
+ const thisRequestId = requestId ;
257
260
loadingLocale = newLocale ;
258
261
if ( loading . settled ) {
259
262
loading = new Deferred ( ) ;
@@ -268,7 +271,7 @@ const setLocale: ((newLocale: string) => void) & {
268
271
} else {
269
272
loadLocale ( newLocale ) . then (
270
273
( mod ) => {
271
- if ( newLocale === loadingLocale ) {
274
+ if ( requestId === thisRequestId ) {
272
275
activeLocale = newLocale ;
273
276
loadingLocale = undefined ;
274
277
templates = mod . templates ;
@@ -281,7 +284,7 @@ const setLocale: ((newLocale: string) => void) & {
281
284
// need to check if the locale is still the one they expected to load.
282
285
} ,
283
286
( err ) => {
284
- if ( newLocale === loadingLocale ) {
287
+ if ( requestId === thisRequestId ) {
285
288
loading . reject ( err ) ;
286
289
dispatchStatusEvent ( {
287
290
status : 'error' ,
You can’t perform that action at this time.
0 commit comments