| Conditions | 1 |
| Paths | 1 |
| Total Lines | 76 |
| 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 PaymentAdditionalDataComponent; |
||
| 5 | var $ = require('jquery'); |
||
| 6 | var mediator = require('oroui/js/mediator'); |
||
| 7 | var BaseComponent = require('oroui/js/app/components/base/component'); |
||
| 8 | |||
| 9 | PaymentAdditionalDataComponent = BaseComponent.extend({ |
||
| 10 | /** |
||
| 11 | * @property {jQuery} |
||
| 12 | */ |
||
| 13 | $el: null, |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @property {Object} |
||
| 17 | */ |
||
| 18 | selectors: { |
||
| 19 | additionalData: '[name$="[additional_data]"]' |
||
| 20 | }, |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @inheritDoc |
||
| 24 | */ |
||
| 25 | constructor: function PaymentAdditionalDataComponent() { |
||
| 26 | PaymentAdditionalDataComponent.__super__.constructor.apply(this, arguments); |
||
| 27 | }, |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @inheritDoc |
||
| 31 | */ |
||
| 32 | initialize: function(options) { |
||
| 33 | this.$el = $(options._sourceElement); |
||
| 34 | |||
| 35 | mediator.on('checkout:payment:additional-data:get', this.onGetAdditionalData, this); |
||
| 36 | mediator.on('checkout:payment:additional-data:set', this.onSetAdditionalData, this); |
||
| 37 | }, |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @param {string} additionalData |
||
| 41 | */ |
||
| 42 | onSetAdditionalData: function(additionalData) { |
||
| 43 | this.getAdditionalDataElement().val(additionalData); |
||
| 44 | }, |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @param {Object} object |
||
| 48 | */ |
||
| 49 | onGetAdditionalData: function(object) { |
||
| 50 | object.additionalData = this.getAdditionalDataElement().val(); |
||
| 51 | }, |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @returns {jQuery|HTMLElement} |
||
| 55 | */ |
||
| 56 | getAdditionalDataElement: function() { |
||
| 57 | return this.$el.find(this.selectors.additionalData); |
||
| 58 | }, |
||
| 59 | |||
| 60 | /** |
||
| 61 | * @inheritDoc |
||
| 62 | */ |
||
| 63 | dispose: function() { |
||
| 64 | if (this.disposed) { |
||
| 65 | return; |
||
| 66 | } |
||
| 67 | |||
| 68 | mediator.off('checkout:payment:additional-data:get', this.onGetAdditionalData, this); |
||
| 69 | mediator.off('checkout:payment:additional-data:set', this.onSetAdditionalData, this); |
||
| 70 | |||
| 71 | PaymentAdditionalDataComponent.__super__.dispose.call(this); |
||
| 72 | } |
||
| 73 | }); |
||
| 74 | |||
| 75 | return PaymentAdditionalDataComponent; |
||
| 76 | }); |
||
| 77 |