Conditions | 1 |
Paths | 1 |
Total Lines | 65 |
Code Lines | 39 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 | 'use strict'; |
||
15 | function ( |
||
16 | $, |
||
17 | BaseForm, |
||
18 | _, |
||
19 | __, |
||
20 | Backbone, |
||
21 | FormBuilder, |
||
22 | template |
||
23 | ) { |
||
24 | return BaseForm.extend({ |
||
25 | template: _.template(template), |
||
26 | |||
27 | initialize(config) { |
||
28 | this.config = config.config; |
||
29 | BaseForm.prototype.initialize.apply(this, arguments); |
||
30 | }, |
||
31 | |||
32 | openModal() { |
||
33 | return FormBuilder.build(this.config.formName).then(modal => { |
||
34 | |||
35 | const rootModel = this.getRoot().model; |
||
36 | var productType, codeToClone; |
||
37 | if (rootModel.has('identifier')) { |
||
38 | productType = 'product'; |
||
39 | codeToClone = rootModel.get('identifier') |
||
40 | } else { |
||
41 | productType = 'model'; |
||
42 | codeToClone = rootModel.get('code') |
||
43 | } |
||
44 | |||
45 | const initialModalState = { |
||
46 | parent: rootModel.get('parent'), |
||
47 | values: {}, |
||
48 | code_to_clone: codeToClone, |
||
49 | type: productType |
||
50 | }; |
||
51 | modal.setData(initialModalState); |
||
52 | modal.open(); |
||
53 | }); |
||
54 | }, |
||
55 | |||
56 | /** |
||
57 | * {@inheritdoc} |
||
58 | */ |
||
59 | getIdentifier: function () { |
||
60 | return this.getFormData().meta.id; |
||
61 | }, |
||
62 | |||
63 | /** |
||
64 | * {@inheritdoc} |
||
65 | */ |
||
66 | render: function () { |
||
67 | if (!this.getFormData().meta) { |
||
68 | return; |
||
|
|||
69 | } |
||
70 | |||
71 | this.$el.html(this.template()); |
||
72 | |||
73 | $('.clone-product-button').on('click', () => { |
||
74 | this.openModal(); |
||
75 | }); |
||
76 | return this; |
||
77 | } |
||
78 | }); |
||
79 | }); |
||
80 |