| Conditions | 1 |
| Paths | 1 |
| Total Lines | 69 |
| 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 | /* |
||
| 10 | define(['jquery'], function($) { |
||
|
|
|||
| 11 | |||
| 12 | 'use strict'; |
||
| 13 | |||
| 14 | var defaults = { |
||
| 15 | options: { |
||
| 16 | data: { |
||
| 17 | contact: null |
||
| 18 | }, |
||
| 19 | selectCallback: function(data) { |
||
| 20 | } |
||
| 21 | }, |
||
| 22 | translations: { |
||
| 23 | title: 'sulu_article.contact-selection-overlay.title' |
||
| 24 | } |
||
| 25 | }; |
||
| 26 | |||
| 27 | return { |
||
| 28 | |||
| 29 | defaults: defaults, |
||
| 30 | |||
| 31 | initialize: function() { |
||
| 32 | var $overlayContainer = $('<div/>'); |
||
| 33 | var $componentContainer = $('<div/>'); |
||
| 34 | this.$el.append($overlayContainer); |
||
| 35 | |||
| 36 | // start overlay |
||
| 37 | this.sandbox.start([{ |
||
| 38 | name: 'overlay@husky', |
||
| 39 | options: { |
||
| 40 | el: $overlayContainer, |
||
| 41 | instanceName: 'contact-selection', |
||
| 42 | openOnStart: true, |
||
| 43 | removeOnClose: true, |
||
| 44 | skin: 'medium', |
||
| 45 | slides: [ |
||
| 46 | { |
||
| 47 | title: this.translations.title, |
||
| 48 | data: $componentContainer, |
||
| 49 | okCallback: this.okCallbackOverlay.bind(this) |
||
| 50 | } |
||
| 51 | ] |
||
| 52 | } |
||
| 53 | }]); |
||
| 54 | |||
| 55 | // start search and datagrid |
||
| 56 | this.sandbox.once('husky.overlay.contact-selection.opened', function() { |
||
| 57 | this.sandbox.start([{ |
||
| 58 | name: 'articles/list/contact-selection/form@suluarticle', |
||
| 59 | options: { |
||
| 60 | el: $componentContainer, |
||
| 61 | data: this.options.data, |
||
| 62 | selectCallback: function(data) { |
||
| 63 | this.options.selectCallback(data); |
||
| 64 | this.sandbox.stop(); |
||
| 65 | }.bind(this) |
||
| 66 | } |
||
| 67 | }]); |
||
| 68 | }.bind(this)); |
||
| 69 | }, |
||
| 70 | |||
| 71 | /** |
||
| 72 | * OK callback of the overlay. |
||
| 73 | */ |
||
| 74 | okCallbackOverlay: function() { |
||
| 75 | this.sandbox.emit('sulu_article.contact-selection.form.get'); |
||
| 76 | } |
||
| 77 | }; |
||
| 78 | }); |
||
| 79 |