Conditions | 1 |
Paths | 12 |
Total Lines | 79 |
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 BackendPageableCollection; |
||
5 | var $ = require('jquery'); |
||
6 | var _ = require('underscore'); |
||
7 | var mediator = require('oroui/js/mediator'); |
||
8 | var PageableCollection = require('orodatagrid/js/pageable-collection'); |
||
9 | var LayoutSubtreeManager = require('oroui/js/layout-subtree-manager'); |
||
10 | var tools = require('oroui/js/tools'); |
||
11 | var error = require('oroui/js/error'); |
||
12 | |||
13 | BackendPageableCollection = PageableCollection.extend({ |
||
14 | /** |
||
15 | * @inheritDoc |
||
16 | */ |
||
17 | constructor: function BackendPageableCollection() { |
||
18 | BackendPageableCollection.__super__.constructor.apply(this, arguments); |
||
19 | }, |
||
20 | |||
21 | /** |
||
22 | * @param {object} options |
||
23 | */ |
||
24 | fetch: function(options) { |
||
25 | this.trigger('beforeFetch', this, options); |
||
26 | |||
27 | this._fetch(options); |
||
28 | }, |
||
29 | |||
30 | /** |
||
31 | * @param {object} options |
||
32 | * @private |
||
33 | */ |
||
34 | _fetch: function(options) { |
||
35 | this.trigger('gridContentUpdate'); |
||
36 | options = _.defaults(options || {}, {reset: true}); |
||
37 | |||
38 | var state = this._checkState(this.state); |
||
39 | |||
40 | var data = options.data || {}; |
||
41 | |||
42 | // set up query params |
||
43 | var url = options.url || _.result(this, 'url') || ''; |
||
44 | var qsi = url.indexOf('?'); |
||
45 | if (qsi !== -1) { |
||
46 | _.extend(data, tools.unpackFromQueryString(url.slice(qsi + 1))); |
||
47 | } |
||
48 | |||
49 | options.data = data; |
||
50 | |||
51 | data.appearanceType = state.appearanceType; |
||
52 | data = this.processQueryParams(data, state); |
||
53 | this.processFiltersParams(data, state); |
||
54 | |||
55 | LayoutSubtreeManager.get('product_datagrid', options.data, function(content) { |
||
56 | var $data = $('<div/>').append(content); |
||
57 | |||
58 | if ($data.find('[data-server-render]').length) { |
||
59 | var options = $data.find('[data-server-render]').data('page-component-options'); |
||
60 | |||
61 | if (options) { |
||
62 | var params = { |
||
63 | responseJSON: options, |
||
64 | gridContent: $data.find('.grid-body') |
||
65 | }; |
||
66 | |||
67 | mediator.trigger('grid-content-loaded', params); |
||
68 | } else { |
||
69 | error.showError(_.__('oro_frontend.datagrid.requires.options')); |
||
70 | } |
||
71 | } else { |
||
72 | error.showError(_.__('oro_frontend.datagrid.requires.data')); |
||
73 | } |
||
74 | }); |
||
75 | } |
||
76 | }); |
||
77 | |||
78 | return BackendPageableCollection; |
||
79 | }); |
||
80 |