Conditions | 19 |
Total Lines | 57 |
Code Lines | 33 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Complex classes like cssEnhancements.js ➔ init often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
1 | import { getGlobalConfiguration, SETTINGS_websiteHideUnusedTabs, SETTINGS_websiteOptimizeListAppearance } from '../configuration/configuration'; |
||
5 | export function init() { |
||
6 | getGlobalConfiguration().getProperty(SETTINGS_websiteHideUnusedTabs, value => { |
||
7 | // if disabled, add class to avoid our css optimizations |
||
8 | if (!value) { |
||
9 | let disableFunc = node => { |
||
10 | if (helper.isHtmlElement(node)) { |
||
11 | let disableNode = node => { |
||
12 | node.classList.add('awp-hide-unused-disabled') |
||
13 | } |
||
14 | |||
15 | if (node.tagName === 'MD-TAB-ITEM') { |
||
16 | disableNode(node); |
||
17 | } |
||
18 | else { |
||
19 | node.querySelectorAll('md-tab-item').forEach(node => disableNode(node)); |
||
20 | } |
||
21 | } |
||
22 | }; |
||
23 | |||
24 | core.registerScript(node => { |
||
25 | disableFunc(node); |
||
26 | }, ".*"); |
||
27 | |||
28 | core.runAfterLoad(() => { |
||
29 | disableFunc(document.body); |
||
30 | }, ".*"); |
||
31 | } |
||
32 | }); |
||
33 | |||
34 | getGlobalConfiguration().getProperty(SETTINGS_websiteOptimizeListAppearance, value => { |
||
35 | // if disabled, add class to avoid our css optimizations |
||
36 | if (!value) { |
||
37 | let disableFunc = node => { |
||
38 | if (helper.isHtmlElement(node)) { |
||
39 | let disableNode = node => { |
||
40 | node.classList.add('awp-list-disabled') |
||
41 | } |
||
42 | |||
43 | if (node.tagName === 'MD-LIST-ITEM') { |
||
44 | disableNode(node); |
||
45 | } |
||
46 | else { |
||
47 | node.querySelectorAll('md-list-item').forEach(node => disableNode(node)); |
||
48 | } |
||
49 | } |
||
50 | } |
||
51 | |||
52 | core.registerScript(node => { |
||
53 | disableFunc(node); |
||
54 | }, ".*"); |
||
55 | |||
56 | core.runAfterLoad(() => { |
||
57 | disableFunc(document.body); |
||
58 | }, ".*"); |
||
59 | } |
||
60 | }); |
||
61 | } |