| Conditions | 2 |
| Paths | 2 |
| Total Lines | 89 |
| 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 | /* |
||
| 16 | (function() { |
||
| 17 | if (!OCA.Circles) { |
||
| 18 | /** |
||
| 19 | * @namespace |
||
| 20 | */ |
||
| 21 | OCA.Circles = {}; |
||
| 22 | } |
||
| 23 | |||
| 24 | OCA.Circles.App = { |
||
| 25 | |||
| 26 | initFileList: function($el) { |
||
| 27 | if (this._fileList) { |
||
| 28 | return this._fileList; |
||
| 29 | } |
||
| 30 | |||
| 31 | this._fileList = new OCA.Circles.FileList( |
||
| 32 | $el, |
||
| 33 | { |
||
| 34 | id: 'circles', |
||
| 35 | scrollContainer: $('#app-content'), |
||
| 36 | fileActions: this._createFileActions(), |
||
| 37 | config: OCA.Files.App.getFilesConfig() |
||
| 38 | } |
||
| 39 | ); |
||
| 40 | |||
| 41 | this._fileList.appName = t('circles', 'Circles'); |
||
| 42 | return this._fileList; |
||
| 43 | }, |
||
| 44 | |||
| 45 | removeFileList: function() { |
||
| 46 | if (this._fileList) { |
||
| 47 | this._fileList.$fileList.empty(); |
||
| 48 | } |
||
| 49 | }, |
||
| 50 | |||
| 51 | _createFileActions: function() { |
||
| 52 | // inherit file actions from the files app |
||
| 53 | var fileActions = new OCA.Files.FileActions(); |
||
| 54 | // note: not merging the legacy actions because legacy apps are not |
||
| 55 | // compatible with the sharing overview and need to be adapted first |
||
| 56 | fileActions.registerDefaultActions(); |
||
| 57 | fileActions.merge(OCA.Files.fileActions); |
||
| 58 | |||
| 59 | if (!this._globalActionsInitialized) { |
||
| 60 | // in case actions are registered later |
||
| 61 | this._onActionsUpdated = _.bind(this._onActionsUpdated, this); |
||
| 62 | OCA.Files.fileActions.on('setDefault.app-circles', this._onActionsUpdated); |
||
| 63 | OCA.Files.fileActions.on('registerAction.app-circles', this._onActionsUpdated); |
||
| 64 | this._globalActionsInitialized = true; |
||
| 65 | } |
||
| 66 | |||
| 67 | // when the user clicks on a folder, redirect to the corresponding |
||
| 68 | // folder in the files app instead of opening it directly |
||
| 69 | fileActions.register('dir', 'Open', OC.PERMISSION_READ, '', function (filename, context) { |
||
| 70 | OCA.Files.App.setActiveView('files', {silent: true}); |
||
| 71 | OCA.Files.App.fileList.changeDirectory(OC.joinPaths(context.$file.attr('data-path'), filename), true, true); |
||
| 72 | }); |
||
| 73 | fileActions.setDefault('dir', 'Open'); |
||
| 74 | return fileActions; |
||
| 75 | }, |
||
| 76 | |||
| 77 | _onActionsUpdated: function(ev) { |
||
| 78 | if (!this._fileList) { |
||
| 79 | return; |
||
| 80 | } |
||
| 81 | |||
| 82 | if (ev.action) { |
||
| 83 | this._fileList.fileActions.registerAction(ev.action); |
||
| 84 | } else if (ev.defaultAction) { |
||
| 85 | this._fileList.fileActions.setDefault( |
||
| 86 | ev.defaultAction.mime, |
||
| 87 | ev.defaultAction.name |
||
| 88 | ); |
||
| 89 | } |
||
| 90 | }, |
||
| 91 | |||
| 92 | /** |
||
| 93 | * Destroy the app |
||
| 94 | */ |
||
| 95 | destroy: function() { |
||
| 96 | OCA.Files.fileActions.off('setDefault.app-circles', this._onActionsUpdated); |
||
| 97 | OCA.Files.fileActions.off('registerAction.app-circles', this._onActionsUpdated); |
||
| 98 | this.removeFileList(); |
||
| 99 | this._fileList = null; |
||
| 100 | delete this._globalActionsInitialized; |
||
| 101 | } |
||
| 102 | }; |
||
| 103 | |||
| 104 | })(); |
||
| 105 | |||
| 114 |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.