Conditions | 1 |
Paths | 1 |
Total Lines | 51 |
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:
1 | import {utils} from '../../../core/utils'; |
||
6 | constructor(container) { |
||
7 | this.container = container; |
||
8 | |||
9 | this.player = null; |
||
10 | |||
11 | this._layouts = { |
||
12 | wrapper: 'data-wrapper', |
||
13 | playButton: 'data-clicktoplay', |
||
14 | container: 'data-container' |
||
15 | }; |
||
16 | |||
17 | this._options = { |
||
18 | autoPlay: false, |
||
19 | controls: true, |
||
20 | coverImage: false, |
||
21 | type: 'file', |
||
22 | embed: false, |
||
23 | videoTypes: { |
||
24 | mp4: false, |
||
25 | webm: false, |
||
26 | ogg: false |
||
27 | }, |
||
28 | }; |
||
29 | |||
30 | this.init(); |
||
31 | |||
32 | this._playerOptions = { |
||
33 | autoplay: this._options.autoPlay, |
||
34 | controls: this._options.controls, |
||
35 | sources: (() => { |
||
36 | let sources = []; |
||
37 | |||
38 | for (let format in this._options.videoTypes) { |
||
39 | let source = this._options.videoTypes[format]; |
||
40 | |||
41 | if (source) { |
||
42 | sources.push({ |
||
43 | src: source, |
||
44 | type: `video/${format}` |
||
45 | }); |
||
46 | } |
||
47 | } |
||
48 | |||
49 | return sources; |
||
50 | })(), |
||
51 | poster: this._options.coverImage |
||
52 | }; |
||
53 | |||
54 | this.bindEvents(); |
||
55 | this.simulateAutoPlay(); |
||
56 | } |
||
57 | |||
126 | export default Video; |
Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.
Consider:
If you or someone else later decides to put another statement in, only the first statement will be executed.
In this case the statement
b = 42
will always be executed, while the logging statement will be executed conditionally.ensures that the proper code will be executed conditionally no matter how many statements are added or removed.