Skip to content

Commit e2cc5c0

Browse files
committed
Refactor dependency management
1 parent 5b7ad93 commit e2cc5c0

10 files changed

Lines changed: 36 additions & 50 deletions

File tree

JavaScript/7-functor.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
'use strict';
22

3-
const arrayChain = (array, prev = null) => {
3+
const metasync = require('metasync');
44

5+
const arrayChain = (array, prev = null) => {
56
let next = null, done = null, fail = null;
67

78
const self = (err, data) => {
@@ -29,15 +30,14 @@ const arrayChain = (array, prev = null) => {
2930
return res;
3031
};
3132

32-
self.map = chain(api.metasync.map);
33-
self.filter = chain(api.metasync.filter);
34-
self.reduce = chain(api.metasync.reduce);
35-
self.each = chain(api.metasync.each);
36-
self.series = chain(api.metasync.series);
37-
self.find = chain(api.metasync.find);
33+
self.map = chain(metasync.map);
34+
self.filter = chain(metasync.filter);
35+
self.reduce = chain(metasync.reduce);
36+
self.each = chain(metasync.each);
37+
self.series = chain(metasync.series);
38+
self.find = chain(metasync.find);
3839

3940
return self;
40-
4141
};
4242

4343
module.exports = {

JavaScript/8-prototype.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
'use strict';
22

3+
const metasync = require('metasync');
4+
35
const async = op => {
46
switch (op) {
5-
case 'map': return api.metasync.map;
6-
case 'filter': return api.metasync.filter;
7-
case 'reduce': return api.metasync.reduce;
8-
case 'each': return api.metasync.each;
9-
case 'series': return api.metasync.series;
10-
case 'find': return api.metasync.find;
7+
case 'map': return metasync.map;
8+
case 'filter': return metasync.filter;
9+
case 'reduce': return metasync.reduce;
10+
case 'each': return metasync.each;
11+
case 'series': return metasync.series;
12+
case 'find': return metasync.find;
1113
}
1214
};
1315

JavaScript/9-build.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
'use strict';
22

3+
const metasync = require('metasync');
4+
35
const async = op => {
46
switch (op) {
5-
case 'map': return api.metasync.map;
6-
case 'filter': return api.metasync.filter;
7-
case 'reduce': return api.metasync.reduce;
8-
case 'each': return api.metasync.each;
9-
case 'series': return api.metasync.series;
10-
case 'find': return api.metasync.find;
7+
case 'map': return metasync.map;
8+
case 'filter': return metasync.filter;
9+
case 'reduce': return metasync.reduce;
10+
case 'each': return metasync.each;
11+
case 'series': return metasync.series;
12+
case 'find': return metasync.find;
1113
}
1214
};
1315

JavaScript/b-compare.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
'use strict';
22

3-
global.api = {
4-
metasync: require('metasync')
5-
};
6-
7-
const implementations = (
8-
['6-promise', '7-functor', '8-prototype', '9-build']
9-
.map(name => `./${name}.js`)
10-
.map(require)
11-
);
3+
const implementations = [
4+
'6-promise', '7-functor', '8-prototype', '9-build'
5+
].map(name => `./${name}.js`).map(require);
126

137
const test = require('./a-test.js');
148

JavaScript/d-build.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
'use strict';
22

3-
global.api = {
4-
metasync: require('metasync')
5-
};
6-
73
const benchmark = require('./c-benchmark');
84
const chainPrototype = require('./9-build');
95
const test = require('./a-test');
6+
107
benchmark.do(40000, 'ProtoBuild', done => test(chainPrototype, done));

JavaScript/d-functor.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
'use strict';
22

3-
global.api = {
4-
metasync: require('metasync')
5-
};
6-
73
const benchmark = require('./c-benchmark');
84
const chainFunctor = require('./7-functor');
95
const test = require('./a-test');
6+
107
benchmark.do(40000, 'Functor', done => test(chainFunctor, done));

JavaScript/d-promise.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
'use strict';
22

3-
global.api = {
4-
metasync: require('metasync')
5-
};
6-
73
const benchmark = require('./c-benchmark');
84
const chainPromise = require('./6-promise');
95
const test = require('./a-test');
6+
107
benchmark.do(40000, 'Promise', done => test(chainPromise, done));

JavaScript/d-prototype.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
'use strict';
22

3-
global.api = {
4-
metasync: require('metasync')
5-
};
6-
73
const benchmark = require('./c-benchmark');
84
const chainPrototype = require('./8-prototype');
95
const test = require('./a-test');
6+
107
benchmark.do(40000, 'Prototype', done => test(chainPrototype, done));

JavaScript/package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

JavaScript/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "chaining",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"author": "Timur Shemsedinov <timur.shemsedinov@gmail.com>",
55
"description": "How Programming Works: Chaining",
66
"license": "MIT",

0 commit comments

Comments
 (0)