Skip to content

Commit 9ca5d44

Browse files
committed
centralize function to create transforms and traces lists
1 parent efa9357 commit 9ca5d44

File tree

1 file changed

+19
-34
lines changed

1 file changed

+19
-34
lines changed

tasks/partial_bundle.js

+19-34
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,23 @@ var allTransforms = constants.allTransforms;
1212
var allTraces = constants.allTraces;
1313
var mainIndex = constants.mainIndex;
1414

15+
function createList(outList, inList, allList, type) {
16+
for(var i = 0; i < inList.length; i++) {
17+
var t = inList[i];
18+
if(
19+
outList.indexOf(t) === -1 // not added before
20+
) {
21+
if(allList.indexOf(t) === -1) {
22+
console.error(t, 'is not a valid ' + type + '!', 'Valid ' + type + 's are:', allList);
23+
} else {
24+
outList.push(t);
25+
}
26+
}
27+
}
28+
29+
return outList.sort();
30+
}
31+
1532
function isFalse(a) {
1633
return (
1734
a === 'none' ||
@@ -39,41 +56,9 @@ if(process.argv.length > 2) {
3956
var traces = inputArray(args.traces, allTraces);
4057
var transforms = inputArray(args.transforms, allTransforms);
4158

42-
var i, t;
43-
44-
var traceList = ['scatter']; // added by default
45-
for(i = 0; i < traces.length; i++) {
46-
t = traces[i];
47-
if(
48-
traceList.indexOf(t) === -1 // not added before
49-
) {
50-
if(allTraces.indexOf(t) === -1) {
51-
console.error(t, 'is not a valid trace!', 'Valid traces are:', allTraces);
52-
} else {
53-
traceList.push(t);
54-
}
55-
}
56-
}
57-
traceList = traceList.sort();
58-
59-
var transformList = [];
60-
for(i = 0; i < transforms.length; i++) {
61-
t = transforms[i];
62-
if(
63-
transformList.indexOf(t) === -1 // not added before
64-
) {
65-
if(allTransforms.indexOf(t) === -1) {
66-
console.error(t, 'is not a valid transform!', 'Valid transforms are:', allTransforms);
67-
} else {
68-
transformList.push(t);
69-
}
70-
}
71-
}
72-
transformList = transformList.sort();
73-
7459
var opts = {
75-
traceList: traceList,
76-
transformList: transformList,
60+
traceList: createList(['scatter'], traces, allTraces, 'trace'),
61+
transformList: createList([], transforms, allTransforms, 'transform'),
7762

7863
name: out,
7964
index: path.join(constants.pathToLib, 'index-' + out + '.js'),

0 commit comments

Comments
 (0)