|
1 | 1 | 'use strict'; |
2 | 2 |
|
3 | | -// const wrap = (before, after, fn) => |
4 | | -// (...args) => after(fn(...before(...args))); |
| 3 | +// const wrap = (before, after, f) => (...args) => after(f(...before(...args))); |
5 | 4 |
|
6 | | -// const wrapAsync = (before, after, beforeCb, afterCb, fn) => |
| 5 | +// const wrapAsync = (before, after, beforeCb, afterCb, f) => |
7 | 6 | // (...args) => { |
8 | | -// const callback = arr[arr.length -1]; |
| 7 | +// const callback = arrs[arrs.length -1]; |
9 | 8 | // if (typeof callback === 'function') { |
10 | 9 | // args[args.length - 1] = (...pars) => |
11 | 10 | // afterCb(callback(...beforeCb(...pars))); |
12 | 11 | // } |
13 | | -// return after(fn(...before(...args))); |
| 12 | +// return after(f(...before(...args))); |
14 | 13 | // }; |
15 | 14 |
|
16 | | -const wrapFunction = fn => { |
17 | | - console.log('Wrap function:', fn.name); |
| 15 | +const wrapFunction = f => { |
| 16 | + console.log('Wrap function:', f.name); |
18 | 17 | return (...args) => { |
19 | | - console.log('Called wrapper for:', fn.name); |
| 18 | + console.log('Called wrapper for:', f.name); |
20 | 19 | console.dir({ args }); |
21 | 20 | if (args.length > 0) { |
22 | 21 | const callback = args[args.length - 1]; |
23 | 22 | if (typeof callback === 'function') { |
24 | 23 | args[args.length - 1] = (...args) => { |
25 | | - console.log('Callback:', fn.name); |
| 24 | + console.log('Callback:', f.name); |
26 | 25 | return callback(...args); |
27 | 26 | }; |
28 | 27 | } |
29 | 28 | } |
30 | | - console.log('Call:', fn.name); |
| 29 | + console.log('Call:', f.name); |
31 | 30 | console.dir(args); |
32 | | - const result = fn(...args); |
33 | | - console.log('Ended wrapper for:', fn.name); |
| 31 | + const result = f(...args); |
| 32 | + console.log('Ended wrapper for:', f.name); |
34 | 33 | console.dir({ result }); |
35 | 34 | return result; |
36 | 35 | }; |
|
0 commit comments