| Conditions | 1 | 
| Paths | 1 | 
| Total Lines | 55 | 
| 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 | define(function(require) { | ||
| 2 | 'use strict'; | ||
| 3 | |||
| 4 | var LineItemView; | ||
| 5 |     var BaseProductView = require('oroproduct/js/app/views/base-product-view'); | ||
| 6 |     var ProductQuantityView = require('oroproduct/js/app/views/product-quantity-editable-view'); | ||
| 7 |     var mediator = require('oroui/js/mediator'); | ||
| 8 |     var _ = require('underscore'); | ||
| 9 | |||
| 10 |     LineItemView = BaseProductView.extend({ | ||
| 11 |         elements: _.extend({}, BaseProductView.prototype.elements, { | ||
| 12 | quantity: '[data-name="field__quantity"]', | ||
| 13 | unit: '[data-name="field__unit"]' | ||
| 14 | }), | ||
| 15 | |||
| 16 | lineItemId: null, | ||
| 17 | |||
| 18 | /** | ||
| 19 | * @inheritDoc | ||
| 20 | */ | ||
| 21 |         constructor: function LineItemView() { | ||
| 22 | LineItemView.__super__.constructor.apply(this, arguments); | ||
| 23 | }, | ||
| 24 | |||
| 25 | /** | ||
| 26 | * @inheritDoc | ||
| 27 | */ | ||
| 28 |         initialize: function(options) { | ||
| 29 | LineItemView.__super__.initialize.apply(this, arguments); | ||
| 30 | this.lineItemId = options.lineItemId; | ||
| 31 | |||
| 32 |             if (this.getElement('quantity').length) { | ||
| 33 |                 var productQuantityView = new ProductQuantityView(_.extend({ | ||
| 34 | el: this.$el.get(0), | ||
| 35 | model: this.model | ||
| 36 | }, options.quantityComponentOptions)); | ||
| 37 | |||
| 38 |                 this.subview('productQuantityView', productQuantityView); | ||
| 39 | this.listenTo(productQuantityView, 'product:quantity-unit:update', this.onQuantityUnitChange); | ||
| 40 | } | ||
| 41 | }, | ||
| 42 | |||
| 43 |         onQuantityUnitChange: function(data) { | ||
| 44 |             mediator.trigger('frontend:shopping-list-item-quantity:update', data); | ||
| 45 | |||
| 46 |             this.trigger('unit-changed', { | ||
| 47 | lineItemId: this.lineItemId, | ||
| 48 |                 product: this.model.get('id'), | ||
| 49 | unit: data.value.unit | ||
| 50 | }); | ||
| 51 | } | ||
| 52 | }); | ||
| 53 | |||
| 54 | return LineItemView; | ||
| 55 | }); | ||
| 56 |