Conditions | 1 |
Paths | 1 |
Total Lines | 56 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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:
1 | /** |
||
6 | ( function( api ) { |
||
7 | var cssTemplate = wp.template( 'lsx-color-scheme' ), |
||
|
|||
8 | skipUpdateCss = false; |
||
9 | |||
10 | api.controlConstructor.select = api.Control.extend( { |
||
11 | ready: function() { |
||
12 | if ( 'color_scheme' === this.id ) { |
||
13 | this.setting.bind( 'change', function( _value ) { |
||
14 | skipUpdateCss = true; |
||
15 | |||
16 | var _colors = colorScheme[_value].colors; |
||
17 | |||
18 | _.each( _colors, function( _color, _setting ) { |
||
19 | if ('function' === typeof api( _setting )) { |
||
20 | api( _setting ).set( _color ); |
||
21 | api.control( _setting ).container.find( '.color-picker-hex' ) |
||
22 | .data( 'data-default-color', _color ) |
||
23 | .wpColorPicker( 'defaultColor', _color ); |
||
24 | } |
||
25 | } ); |
||
26 | |||
27 | skipUpdateCss = false; |
||
28 | updateCSS(); |
||
29 | } ); |
||
30 | } |
||
31 | } |
||
32 | } ); |
||
33 | |||
34 | // Generate the CSS for the current Color Scheme. |
||
35 | function updateCSS() { |
||
36 | if (skipUpdateCss) { |
||
37 | return; |
||
38 | } |
||
39 | |||
40 | var __scheme = api( 'color_scheme' )(), |
||
41 | __css, |
||
42 | __colors = colorScheme[ __scheme ].colors; |
||
43 | |||
44 | // Merge in color scheme overrides. |
||
45 | _.each( colorSchemeKeys, function( __setting ) { |
||
46 | if ('function' === typeof api( __setting )) { |
||
47 | __colors[ __setting ] = api( __setting )(); |
||
48 | } |
||
49 | } ); |
||
50 | |||
51 | __css = cssTemplate( __colors ); |
||
52 | api.previewer.send( 'update-color-scheme-css', __css ); |
||
53 | } |
||
54 | |||
55 | // Update the CSS whenever a color setting is changed. |
||
56 | _.each( colorSchemeKeys, function( __setting ) { |
||
57 | api( __setting, function( __setting ) { |
||
58 | __setting.bind( updateCSS ); |
||
59 | } ); |
||
60 | } ); |
||
61 | } )( wp.customize ); |
||
62 |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.