Test Setup Failed
Push — master ( 982d9a...a2862f )
by
unknown
03:40
created

select2-channel-aware-view-factory.js ➔ ... ➔   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 56

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 56
rs 9.7251
c 0
b 0
f 0

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([
2
    'underscore'
3
], function(_) {
4
    'use strict';
5
6
    return function(BaseSelect2View) {
7
        var Select2ChannelAwareView = BaseSelect2View.extend({
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable Select2ChannelAwareView already seems to be declared on line 18. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
8
            $channelSelector: null,
9
10
            requiredOptions: [
11
                '$channelSelector',
12
                'additionalParamsCb'
13
            ],
14
15
            /**
16
             * @inheritDoc
17
             */
18
            constructor: function Select2ChannelAwareView() {
19
                Select2ChannelAwareView.__super__.constructor.apply(this, arguments);
20
            },
21
22
            /**
23
             * @inheritDoc
24
             */
25
            initialize: function(options) {
26
                Select2ChannelAwareView.__super__.initialize.apply(this, arguments);
27
28
                _.each(this.requiredOptions, function(optionName) {
29
                    if (!_.has(options, optionName)) {
30
                        throw new Error('Required option "' + optionName + '" not found.');
31
                    }
32
                });
33
34
                var updateData = _.bind(function(initialCall) {
35
                    initialCall = initialCall || false;
36
                    this.$el.data('select2_query_additional_params', options.additionalParamsCb());
37
38
                    if (!initialCall) {
39
                        this.$el.val(null).change();
40
                    }
41
                }, this);
42
43
                this.$channelSelector = options.$channelSelector;
44
                this.$channelSelector.on('change' + this.eventNamespace(), updateData);
45
                updateData(true);
46
            },
47
48
            dispose: function() {
49
                if (this.disposed) {
50
                    return;
51
                }
52
53
                this.$channelSelector.off(this.eventNamespace());
54
                delete this.$channelSelector;
55
56
                Select2ChannelAwareView.__super__.dispose.apply(this, arguments);
57
            }
58
        });
59
60
        return Select2ChannelAwareView;
61
    };
62
});
63