We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Conditions | 1 |
Paths | 3 |
Total Lines | 72 |
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 | 'use strict'; |
||
3 | define(['jquery', 'marionette', 'lodash', 'core/modal'], function($, Mn, _, Modal) { |
||
4 | return { |
||
5 | alert: function(message) { |
||
6 | let m = Modal.extend({ |
||
7 | 'template': message, |
||
8 | 'modal': { |
||
9 | 'buttons': { |
||
10 | 'Close': { |
||
11 | 'close': true, |
||
12 | 'class': 'info', |
||
13 | 'flat': true |
||
14 | }, |
||
15 | } |
||
16 | } |
||
17 | }); |
||
18 | |||
19 | let v = new m(); |
||
20 | |||
21 | v.render(); |
||
22 | |||
23 | return v; |
||
24 | }, |
||
25 | confirm: function(message, callback) { |
||
26 | let m = Modal.extend({ |
||
27 | 'template': message, |
||
28 | 'modal': { |
||
29 | 'buttons': { |
||
30 | 'Cancel': { |
||
31 | 'close': true, |
||
32 | 'class': 'warning', |
||
33 | 'flat': true |
||
34 | }, |
||
35 | 'OK': { |
||
36 | 'class': 'success', |
||
37 | 'flat': true, |
||
38 | 'save': true |
||
39 | } |
||
40 | }, |
||
41 | 'events': { |
||
42 | 'modal:save': 'confirm' |
||
43 | } |
||
44 | }, |
||
45 | confirm: function() { |
||
46 | this.showLoader(); |
||
47 | |||
48 | let close = _.bind(function() { |
||
49 | this.$el.modal('hide'); |
||
50 | this.hideLoader(); |
||
51 | }, this); |
||
52 | |||
53 | if (_.isFunction(callback)) { |
||
54 | let response = callback.call(this, true); |
||
55 | |||
56 | if (response instanceof Promise || response instanceof $.Deferred || _.result(response, 'then')) { |
||
57 | response.then(close); |
||
58 | } else { |
||
59 | close.apply(this) |
||
60 | } |
||
61 | } else { |
||
62 | close.apply(this); |
||
63 | } |
||
64 | } |
||
65 | }); |
||
66 | |||
67 | let v = new m(); |
||
68 | |||
69 | v.render(); |
||
70 | |||
71 | return v; |
||
72 | } |
||
73 | }; |
||
74 | }); |