| Conditions | 1 |
| Paths | 8 |
| Total Lines | 64 |
| 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 | import path from 'path' |
||
| 13 | var p = new Promise((resolve, reject) => { |
||
| 14 | abeExtend.hooks.instance.trigger('beforePublish', json, filePath, tplPath) |
||
| 15 | var p1 = new Promise((resolve) => { |
||
| 16 | cmsOperations.save.save( |
||
| 17 | path.join(config.root, config.draft.url, filePath.replace(config.root)), |
||
| 18 | tplPath, |
||
| 19 | json, |
||
| 20 | '', |
||
| 21 | 'draft', |
||
| 22 | null, |
||
| 23 | 'publish') |
||
| 24 | .then(() => { |
||
| 25 | resolve() |
||
| 26 | }).catch(function(e) { |
||
| 27 | console.error(e) |
||
| 28 | }) |
||
| 29 | }) |
||
| 30 | |||
| 31 | p1.then((resSave) => { |
||
| 32 | cmsOperations.save.save( |
||
| 33 | path.join(config.root, config.draft.url, filePath.replace(config.root)), |
||
| 34 | tplPath, |
||
| 35 | json, |
||
| 36 | '', |
||
| 37 | 'publish', |
||
| 38 | resSave, |
||
| 39 | 'publish') |
||
| 40 | .then((resSave) => { |
||
| 41 | var result |
||
| 42 | if(typeof resSave.error !== 'undefined' && resSave.error !== null ){ |
||
| 43 | result = { |
||
| 44 | success: 0, |
||
| 45 | error: resSave.error |
||
| 46 | } |
||
| 47 | } else if(typeof resSave.reject !== 'undefined' && resSave.reject !== null){ |
||
| 48 | result = resSave |
||
| 49 | } else if(typeof resSave.json !== 'undefined' && resSave.json !== null){ |
||
| 50 | result = { |
||
| 51 | success: 1, |
||
| 52 | json: resSave.json |
||
| 53 | } |
||
| 54 | } |
||
| 55 | abeExtend.hooks.instance.trigger('afterPublish', result) |
||
|
|
|||
| 56 | Manager.instance.updateList() |
||
| 57 | resolve(result) |
||
| 58 | }).catch(function(e) { |
||
| 59 | console.error('post-publish.js', e) |
||
| 60 | var result = { |
||
| 61 | success: 0, |
||
| 62 | error: 'post-publish error' |
||
| 63 | } |
||
| 64 | abeExtend.hooks.instance.trigger('afterPublish', result) |
||
| 65 | resolve(result) |
||
| 66 | }) |
||
| 67 | }).catch(function(e) { |
||
| 68 | console.error('post-publish.js', e) |
||
| 69 | var result = { |
||
| 70 | success: 0, |
||
| 71 | error: 'post-publish error' |
||
| 72 | } |
||
| 73 | abeExtend.hooks.instance.trigger('afterPublish', result) |
||
| 74 | resolve(result) |
||
| 75 | }) |
||
| 76 | }) |
||
| 77 | |||
| 106 | } |