Skip to content

Commit 4690c75

Browse files
committed
fix(compiler): move symbols sort from sprite-factory to compiler
1 parent 70c1475 commit 4690c75

2 files changed

Lines changed: 17 additions & 12 deletions

File tree

packages/svg-baker/lib/compiler.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,20 @@ const defaultConfig = {
1616
};
1717

1818
class Compiler {
19+
static sortSymbols(symbols) {
20+
symbols.sort((leftSymbol, rightSymbol) => {
21+
const leftId = leftSymbol.id;
22+
const rightId = rightSymbol.id;
23+
24+
if (leftId === rightId) {
25+
return 0;
26+
}
27+
return leftId < rightId ? -1 : 1;
28+
});
29+
30+
return symbols;
31+
}
32+
1933
constructor(cfg = {}) {
2034
const config = this.config = merge(defaultConfig, cfg);
2135
this.rules = new RuleSet(config.rules);
@@ -43,10 +57,12 @@ class Compiler {
4357
return SpriteSymbol.create(options).then((newSymbol) => {
4458
if (!existing) {
4559
symbols.push(newSymbol);
60+
Compiler.sortSymbols(symbols);
4661
return newSymbol;
4762
}
4863

4964
symbols[existingIndex] = newSymbol;
65+
Compiler.sortSymbols(symbols);
5066

5167
return Promise.map(allExceptCurrent, ({ symbol, index }) => {
5268
const opts = { id: symbol.id, request: symbol.request, content, factory };

packages/svg-baker/lib/sprite-factory.js

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,7 @@ const defaultConfig = {
2424
*/
2525
function createSprite(config = {}) {
2626
const cfg = merge(defaultConfig, config);
27-
const symbols = [].concat(cfg.symbols);
28-
29-
symbols.sort((leftSymbol, rightSymbol) => {
30-
const leftId = leftSymbol.id;
31-
const rightId = rightSymbol.id;
32-
33-
if (leftId === rightId) {
34-
return 0;
35-
}
36-
return leftId < rightId ? -1 : 1;
37-
});
38-
27+
const symbols = cfg.symbols;
3928
const trees = symbols.map(s => s.tree);
4029
let usages = [];
4130

0 commit comments

Comments
 (0)