Conditions | 4 |
Paths | 16 |
Total Lines | 99 |
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 | ;(function(window) { |
||
2 | 'use strict'; |
||
3 | |||
4 | if (window.snapshots.config.isRecordingSnapshots && !window.snapshots.config.currentStep) { |
||
5 | console.log('📹 This session is currently being recorded. Session ID: ' + window.snapshots.config.sessionId); |
||
|
|||
6 | } |
||
7 | |||
8 | if (window.snapshots.config.currentStep) { |
||
9 | console.log('📹 Watching step ' + window.snapshots.config.currentStep + ' of recorded session ' + window.snapshots.config.sessionId); |
||
10 | } |
||
11 | |||
12 | window.snapshots.request = function(url, callbackSuccess, callbackError) { |
||
13 | var xhr = new XMLHttpRequest(); |
||
14 | xhr.open('GET', url); |
||
15 | xhr.send(null); |
||
16 | xhr.onreadystatechange = function () { |
||
17 | if (xhr.readyState === 4) { |
||
18 | if (xhr.status === 200) { |
||
19 | callbackSuccess(); |
||
20 | } else { |
||
21 | callbackError(); |
||
22 | } |
||
23 | } |
||
24 | }; |
||
25 | }; |
||
26 | |||
27 | window.snapshots.record = function() { |
||
28 | var me = this; |
||
29 | |||
30 | if (me.config.isRecordingSnapshots || !me.config.startUrl) { |
||
31 | console.log('⚠️ Already recording or missing config.'); |
||
32 | |||
33 | return; |
||
34 | } |
||
35 | |||
36 | me.request( |
||
37 | me.config.startUrl, |
||
38 | function () { |
||
39 | me.config.isRecordingSnapshots = true; |
||
40 | |||
41 | console.log('▶️️ Recording of session starting next request. Session ID: ' + me.config.sessionId); |
||
42 | }, |
||
43 | function () { |
||
44 | console.log('⚠️ Error while starting the recording of session.'); |
||
45 | } |
||
46 | ); |
||
47 | }; |
||
48 | |||
49 | window.snapshots.stop = function() { |
||
50 | var me = this; |
||
51 | |||
52 | if (!me.config.isRecordingSnapshots || !me.config.stopUrl) { |
||
53 | console.log('⚠️ Not recording at the moment.'); |
||
54 | |||
55 | return; |
||
56 | } |
||
57 | |||
58 | me.request( |
||
59 | me.config.stopUrl, |
||
60 | function () { |
||
61 | me.config.isRecordingSnapshots = false; |
||
62 | |||
63 | console.log('✋️️ Stopped recording current session.'); |
||
64 | }, |
||
65 | function () { |
||
66 | console.log('⚠️ Error while stopping the recording of session.'); |
||
67 | } |
||
68 | ); |
||
69 | }; |
||
70 | |||
71 | window.snapshots.next = function() { |
||
72 | var me = this; |
||
73 | |||
74 | if (!me.config.nextUrl) { |
||
75 | console.log('⚠️ No next snapshot recorded or currently not watching session.'); |
||
76 | |||
77 | return; |
||
78 | } |
||
79 | |||
80 | console.log('➡️️ Loading next snapshot.'); |
||
81 | |||
82 | window.location.href = me.config.nextUrl; |
||
83 | }; |
||
84 | |||
85 | window.snapshots.prev = function() { |
||
86 | var me = this; |
||
87 | |||
88 | if (!me.config.prevUrl) { |
||
89 | console.log('⚠️ No previous snapshot recorded or currently not watching session.'); |
||
90 | |||
91 | return; |
||
92 | } |
||
93 | |||
94 | console.log('⬅️️ Loading previous snapshot.'); |
||
95 | |||
96 | window.location.href = me.config.prevUrl; |
||
97 | }; |
||
98 | |||
99 | })(window); |