Conditions | 1 |
Paths | 1 |
Total Lines | 77 |
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 InlineEditableViewComponent = require('oroform/js/app/components/inline-editable-view-component'); |
||
5 | var ShoppingListCollectionService = require('oroshoppinglist/js/shoppinglist-collection-service'); |
||
6 | var mediator = require('oroui/js/mediator'); |
||
7 | var ShoppingListTitleInlineEditableViewComponent; |
||
8 | |||
9 | ShoppingListTitleInlineEditableViewComponent = InlineEditableViewComponent.extend({ |
||
10 | |||
11 | eventChannelId: null, |
||
12 | |||
13 | shoppingListCollection: null, |
||
14 | |||
15 | /** |
||
16 | * @inheritDoc |
||
17 | */ |
||
18 | constructor: function ShoppingListTitleInlineEditableViewComponent() { |
||
19 | ShoppingListTitleInlineEditableViewComponent.__super__.constructor.apply(this, arguments); |
||
20 | }, |
||
21 | |||
22 | /** |
||
23 | * @param {Object} options |
||
24 | */ |
||
25 | initialize: function(options) { |
||
26 | this.$el = options._sourceElement; |
||
27 | this.shoppingListId = options.metadata.broadcast_parameters.id; |
||
28 | this.eventChannelId = options.eventChannelId; |
||
29 | ShoppingListTitleInlineEditableViewComponent.__super__.initialize.apply(this, arguments); |
||
30 | |||
31 | // listening to generic inline editor's events and repackaging them |
||
32 | // into specific shopping list events |
||
33 | mediator.on('inlineEditor:' + this.eventChannelId + ':update', this.repackageEvent, this); |
||
34 | |||
35 | ShoppingListCollectionService.shoppingListCollection.done((function(collection) { |
||
36 | this.shoppingListCollection = collection; |
||
37 | }).bind(this)); |
||
38 | }, |
||
39 | |||
40 | getViewOptions: function() { |
||
41 | var options = ShoppingListTitleInlineEditableViewComponent.__super__.getViewOptions.apply(this); |
||
42 | |||
43 | if (!this.inlineEditingOptions.enable) { |
||
44 | options.autoRender = false; |
||
45 | } |
||
46 | |||
47 | return options; |
||
48 | }, |
||
49 | |||
50 | /** |
||
51 | * |
||
52 | * @param data |
||
53 | */ |
||
54 | repackageEvent: function(data) { |
||
55 | var shoppingListId = this.shoppingListId; |
||
56 | this.shoppingListCollection.each(function(model) { |
||
57 | if (model.get('id') === shoppingListId) { |
||
58 | model.set('label', data.label); |
||
59 | } |
||
60 | }); |
||
61 | }, |
||
62 | |||
63 | dispose: function() { |
||
64 | if (this.disposed) { |
||
65 | return; |
||
66 | } |
||
67 | |||
68 | delete this.shoppingListCollection; |
||
69 | this.$el.off(); |
||
70 | mediator.off('inlineEditor:' + this.eventChannelId + ':update', this.repackageEvent, this); |
||
71 | |||
72 | ShoppingListTitleInlineEditableViewComponent.__super__.dispose.call(this); |
||
73 | } |
||
74 | }); |
||
75 | |||
76 | return ShoppingListTitleInlineEditableViewComponent; |
||
77 | }); |
||
78 |