| Conditions | 1 |
| Paths | 4 |
| 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 ShippingMethodsView; |
||
| 5 | var BaseView = require('oroui/js/app/views/base/view'); |
||
| 6 | var _ = require('underscore'); |
||
| 7 | var $ = require('jquery'); |
||
| 8 | var NumberFormatter = require('orolocale/js/formatter/number'); |
||
| 9 | var mediator = require('oroui/js/mediator'); |
||
| 10 | |||
| 11 | ShippingMethodsView = BaseView.extend({ |
||
| 12 | autoRender: true, |
||
| 13 | |||
| 14 | options: { |
||
| 15 | template: '' |
||
| 16 | }, |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @inheritDoc |
||
| 20 | */ |
||
| 21 | constructor: function ShippingMethodsView() { |
||
| 22 | ShippingMethodsView.__super__.constructor.apply(this, arguments); |
||
| 23 | }, |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @inheritDoc |
||
| 27 | */ |
||
| 28 | initialize: function(options) { |
||
| 29 | ShippingMethodsView.__super__.initialize.apply(this, arguments); |
||
| 30 | |||
| 31 | this.options = _.defaults(options || {}, this.options); |
||
| 32 | this.options.template = _.template(this.options.template); |
||
| 33 | |||
| 34 | mediator.on('transition:failed', this.render.bind(this, [])); |
||
| 35 | }, |
||
| 36 | |||
| 37 | render: function(options) { |
||
| 38 | this.updateShippingMethods(options); |
||
| 39 | mediator.trigger('layout:adjustHeight'); |
||
| 40 | mediator.trigger('checkout:shipping-method:rendered'); |
||
| 41 | }, |
||
| 42 | |||
| 43 | updateShippingMethods: function(options) { |
||
| 44 | var $el = $(this.options.template({ |
||
| 45 | methods: options || this.options.data.methods, |
||
| 46 | currentShippingMethod: this.options.data.currentShippingMethod, |
||
| 47 | currentShippingMethodType: this.options.data.currentShippingMethodType, |
||
| 48 | formatter: NumberFormatter |
||
| 49 | })); |
||
| 50 | this.$el.html($el); |
||
| 51 | } |
||
| 52 | }); |
||
| 53 | |||
| 54 | return ShippingMethodsView; |
||
| 55 | }); |
||
| 56 |