Skip to content

Commit 00536f4

Browse files
committed
lint: split registry switch block into routines
1 parent bf28ad9 commit 00536f4

File tree

1 file changed

+30
-24
lines changed

1 file changed

+30
-24
lines changed

src/plot_api/register.js

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,37 +29,43 @@ module.exports = function register(_modules) {
2929

3030
switch(newModule.moduleType) {
3131
case 'trace':
32-
Plots.register(newModule, newModule.name, newModule.categories, newModule.meta);
33-
34-
if(!Plots.subplotsRegistry[newModule.basePlotModule.name]) {
35-
Plots.registerSubplot(newModule.basePlotModule);
36-
}
37-
32+
registerTraceModule(newModule);
3833
break;
3934

4035
case 'transform':
41-
if(typeof newModule.name !== 'string') {
42-
throw new Error('Transform module *name* must be a string.');
43-
}
44-
45-
var prefix = 'Transform module ' + newModule.name;
46-
47-
if(typeof newModule.transform !== 'function') {
48-
throw new Error(prefix + ' is missing a *transform* function.');
49-
}
50-
if(!Lib.isPlainObject(newModule.attributes)) {
51-
Lib.log(prefix + ' registered without an *attributes* object.');
52-
}
53-
if(typeof newModule.supplyDefaults !== 'function') {
54-
Lib.log(prefix + ' registered without a *supplyDefaults* function.');
55-
}
56-
57-
Plots.transformsRegistry[newModule.name] = newModule;
58-
36+
registerTransformModule(newModule);
5937
break;
6038

6139
default:
6240
throw new Error('Invalid module was attempted to be registered!');
6341
}
6442
}
6543
};
44+
45+
function registerTraceModule(newModule) {
46+
Plots.register(newModule, newModule.name, newModule.categories, newModule.meta);
47+
48+
if(!Plots.subplotsRegistry[newModule.basePlotModule.name]) {
49+
Plots.registerSubplot(newModule.basePlotModule);
50+
}
51+
}
52+
53+
function registerTransformModule(newModule) {
54+
if(typeof newModule.name !== 'string') {
55+
throw new Error('Transform module *name* must be a string.');
56+
}
57+
58+
var prefix = 'Transform module ' + newModule.name;
59+
60+
if(typeof newModule.transform !== 'function') {
61+
throw new Error(prefix + ' is missing a *transform* function.');
62+
}
63+
if(!Lib.isPlainObject(newModule.attributes)) {
64+
Lib.log(prefix + ' registered without an *attributes* object.');
65+
}
66+
if(typeof newModule.supplyDefaults !== 'function') {
67+
Lib.log(prefix + ' registered without a *supplyDefaults* function.');
68+
}
69+
70+
Plots.transformsRegistry[newModule.name] = newModule;
71+
}

0 commit comments

Comments
 (0)