Test Setup Failed
Push — master ( cd1dab...2a689d )
by
unknown
03:51
created

frontend-product-sidebar-component.js ➔ define   B

Complexity

Conditions 1
Paths 2

Size

Total Lines 76

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 2
nop 1
dl 0
loc 76
rs 8.9667
c 0
b 0
f 0

6 Functions

Rating   Name   Duplication   Size   Complexity  
A frontend-product-sidebar-component.js ➔ ... ➔ BaseComponent.extend.onCurrenciesChange 0 3 1
A frontend-product-sidebar-component.js ➔ ... ➔ BaseComponent.extend.initialize 0 7 1
A frontend-product-sidebar-component.js ➔ ... ➔ BaseComponent.extend.dispose 0 9 2
A frontend-product-sidebar-component.js ➔ ... ➔ BaseComponent.extend.onShowTierPricesChange 0 3 1
A frontend-product-sidebar-component.js ➔ ... ➔ FrontendProductSidebarComponent 0 3 1
A frontend-product-sidebar-component.js ➔ ... ➔ BaseComponent.extend.triggerSidebarChanged 0 14 1

How to fix   Long Method   

Long Method

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:

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