Skip to content

Commit 643d13d

Browse files
committed
Bundle: Enhcance bundleMapQueue logic (amend)
This amends commit 64dd766. Ref #70
1 parent 47d67f2 commit 643d13d

2 files changed

Lines changed: 17 additions & 20 deletions

File tree

src/bundle/lookup.js

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ define([
22
"../core/likely_subtags",
33
"../core/remove_likely_subtags",
44
"../core/subtags",
5-
], function( coreLikelySubtags, coreRemoveLikelySubtags, coreSubtags ) {
5+
"../util/array/for_each"
6+
], function( coreLikelySubtags, coreRemoveLikelySubtags, coreSubtags, arrayForEach ) {
67

78
/**
89
* bundleLookup( minLanguageId )
@@ -17,28 +18,24 @@ define([
1718
var availableBundleMap = Cldr._availableBundleMap,
1819
availableBundleMapQueue = Cldr._availableBundleMapQueue;
1920

20-
if (availableBundleMapQueue.length) {
21-
while (availableBundleMapQueue.length > 0) {
22-
const bundle = availableBundleMapQueue.shift();
23-
if (!bundle) {
24-
break;
25-
}
26-
21+
if ( availableBundleMapQueue.length ) {
22+
arrayForEach( availableBundleMapQueue, function( bundle ) {
2723
var existing, maxBundle, minBundle, subtags;
28-
subtags = coreSubtags(bundle);
29-
maxBundle = coreLikelySubtags(Cldr, cldr, subtags);
30-
if (typeof maxBundle === "undefined") {
31-
throw new Error(`Could not find likelySubtags for ${bundle}`);
24+
subtags = coreSubtags( bundle );
25+
maxBundle = coreLikelySubtags( Cldr, cldr, subtags );
26+
if ( maxBundle === undefined ) {
27+
availableBundleMapQueue.splice( i, 1 );
28+
throw new Error( "Could not find likelySubtags for " + bundle );
3229
}
33-
34-
minBundle = coreRemoveLikelySubtags(Cldr, cldr, maxBundle);
35-
minBundle = minBundle.join(Cldr.localeSep);
36-
existing = availableBundleMap[minBundle];
37-
if (existing && existing.length < bundle.length) {
30+
minBundle = coreRemoveLikelySubtags( Cldr, cldr, maxBundle );
31+
minBundle = minBundle.join( Cldr.localeSep );
32+
existing = availableBundleMap[ minBundle ];
33+
if ( existing && existing.length < bundle.length ) {
3834
return;
3935
}
40-
availableBundleMap[minBundle] = bundle;
41-
}
36+
availableBundleMap[ minBundle ] = bundle;
37+
});
38+
Cldr._availableBundleMapQueue = [];
4239
}
4340

4441
return availableBundleMap[ minLanguageId ] || null;

test/unit/bundle/lookup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ define([
9393
new Cldr("bg");
9494
}).to.throw();
9595

96-
expect(Cldr._availableBundleMapQueue).to.eql(["sr"]);
96+
expect(Cldr._availableBundleMapQueue).to.eql(["bg", "sr"]);
9797

9898
// the invalid bundle has been removed so we can load bg
9999
new Cldr("bg");

0 commit comments

Comments
 (0)