| Conditions | 1 |
| Paths | 1 |
| Total Lines | 69 |
| 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 | // Directives |
||
| 12 | Directives.prototype.defineConfirm = function () { |
||
| 13 | const _this = this |
||
| 14 | const DirectiveDefinition = {} |
||
| 15 | |||
| 16 | const clickHandler = function (event, el, binding) { |
||
| 17 | event.preventDefault() |
||
| 18 | event.stopImmediatePropagation() |
||
| 19 | |||
| 20 | let confirmMessage = (function () { |
||
| 21 | if (binding.value && binding.value.message) { |
||
| 22 | return binding.value.message |
||
| 23 | } |
||
| 24 | return typeof binding.value === 'string' ? binding.value : null |
||
| 25 | })() |
||
| 26 | |||
| 27 | let thenCallback = (function () { |
||
| 28 | if (binding.value && binding.value.ok) { |
||
| 29 | return binding.value.ok |
||
| 30 | } else { |
||
| 31 | return () => { |
||
| 32 | el.removeEventListener('click', el.VuejsDialog.clickHandler, true) |
||
| 33 | |||
| 34 | _this.Vue.nextTick(() => { |
||
| 35 | (function (node) { |
||
| 36 | if (document.createEvent) { |
||
| 37 | let evt = document.createEvent('MouseEvents'); |
||
| 38 | evt.initEvent('click', true, false); |
||
| 39 | node.dispatchEvent(evt); |
||
| 40 | } else if (document.createEventObject) { |
||
| 41 | node.fireEvent('onclick'); |
||
| 42 | } else if (typeof node.onclick === 'function') { |
||
| 43 | node.onclick(); |
||
| 44 | } |
||
| 45 | })(el) |
||
| 46 | |||
| 47 | el.addEventListener('click', el.VuejsDialog.clickHandler, true) |
||
| 48 | }) |
||
| 49 | } |
||
| 50 | } |
||
| 51 | })() |
||
| 52 | |||
| 53 | let catchCallback = (function () { |
||
| 54 | if (binding.value && binding.value.cancel) { |
||
| 55 | return binding.value.cancel |
||
| 56 | } |
||
| 57 | return noop |
||
| 58 | })() |
||
| 59 | |||
| 60 | _this.Vue.dialog.confirm(confirmMessage).then(thenCallback).catch(catchCallback) |
||
| 61 | } |
||
| 62 | |||
| 63 | DirectiveDefinition.bind = (el, binding) => { |
||
| 64 | if (el.VuejsDialog === undefined) { |
||
| 65 | el.VuejsDialog = {} |
||
| 66 | } |
||
| 67 | |||
| 68 | el.VuejsDialog.clickHandler = function clickEventHandler(event) { |
||
| 69 | clickHandler(event, el, binding) |
||
| 70 | } |
||
| 71 | |||
| 72 | el.addEventListener('click', el.VuejsDialog.clickHandler, true) |
||
| 73 | } |
||
| 74 | |||
| 75 | DirectiveDefinition.unbind = (el) => { |
||
| 76 | el.removeEventListener('click', el.VuejsDialog.clickHandler, true) |
||
| 77 | } |
||
| 78 | |||
| 79 | return DirectiveDefinition |
||
| 80 | } |
||
| 81 | |||
| 87 |