| Conditions | 1 |
| Paths | 2 |
| 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 FrontendProductSidebarComponent; |
||
| 5 | var $ = require('jquery'); |
||
| 6 | var _ = require('underscore'); |
||
| 7 | var BaseComponent = require('oroui/js/app/components/base/component'); |
||
| 8 | var mediator = require('oroui/js/mediator'); |
||
| 9 | |||
| 10 | FrontendProductSidebarComponent = BaseComponent.extend({ |
||
| 11 | /** |
||
| 12 | * @property {Object} |
||
| 13 | */ |
||
| 14 | options: { |
||
| 15 | currenciesSelector: '', |
||
| 16 | showTierPricesSelector: '', |
||
| 17 | sidebarAlias: 'frontend-products-sidebar' |
||
| 18 | }, |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @inheritDoc |
||
| 22 | */ |
||
| 23 | constructor: function FrontendProductSidebarComponent() { |
||
| 24 | FrontendProductSidebarComponent.__super__.constructor.apply(this, arguments); |
||
| 25 | }, |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @inheritDoc |
||
| 29 | */ |
||
| 30 | initialize: function(options) { |
||
| 31 | this.options = _.defaults(options || {}, this.options); |
||
| 32 | |||
| 33 | this.options._sourceElement |
||
| 34 | .on('change', this.options.currenciesSelector, _.bind(this.onCurrenciesChange, this)) |
||
| 35 | .on('change', this.options.showTierPricesSelector, _.bind(this.onShowTierPricesChange, this)); |
||
| 36 | }, |
||
| 37 | |||
| 38 | onCurrenciesChange: function() { |
||
| 39 | this.triggerSidebarChanged(true); |
||
| 40 | }, |
||
| 41 | |||
| 42 | onShowTierPricesChange: function() { |
||
| 43 | this.triggerSidebarChanged(false); |
||
| 44 | }, |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @param {Boolean} widgetReload |
||
| 48 | */ |
||
| 49 | triggerSidebarChanged: function(widgetReload) { |
||
| 50 | var currency = $(this.options.currenciesSelector).val(); |
||
| 51 | |||
| 52 | var params = { |
||
| 53 | priceCurrencies: currency, |
||
| 54 | showTierPrices: $(this.options.showTierPricesSelector).prop('checked'), |
||
| 55 | saveState: true |
||
| 56 | }; |
||
| 57 | |||
| 58 | mediator.trigger( |
||
| 59 | 'grid-sidebar:change:' + this.options.sidebarAlias, |
||
| 60 | {widgetReload: Boolean(widgetReload), params: params} |
||
| 61 | ); |
||
| 62 | }, |
||
| 63 | |||
| 64 | dispose: function() { |
||
| 65 | if (this.disposed) { |
||
| 66 | return; |
||
| 67 | } |
||
| 68 | |||
| 69 | this.options._sourceElement.off(); |
||
| 70 | |||
| 71 | FrontendProductSidebarComponent.__super__.dispose.call(this); |
||
| 72 | } |
||
| 73 | }); |
||
| 74 | |||
| 75 | return FrontendProductSidebarComponent; |
||
| 76 | }); |
||
| 77 |