Skip to content

Commit a88ab1b

Browse files
committed
Use intermediate variables
1 parent 1153c93 commit a88ab1b

2 files changed

Lines changed: 9 additions & 9 deletions

File tree

‎JavaScript/4-pipeline.js‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@ const appendTrace = (context, step) => {
99
return [...trace, step];
1010
};
1111

12-
const pipeline =
13-
(...steps) =>
14-
(context) => {
15-
const initial = Promise.resolve(context);
16-
const next = (chain, mw) => chain.then((ctx) => mw(ctx));
17-
return steps.reduce(next, initial);
18-
};
12+
const pipeline = (...steps) => (context) => {
13+
const initial = Promise.resolve(context);
14+
const next = (chain, middleware) =>
15+
chain.then((ctx) => middleware(ctx));
16+
return steps.reduce(next, initial);
17+
};
1918

2019
const tracing = (context) => {
2120
const { console } = context;

‎JavaScript/6-immutable.js‎

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

3-
const createContext = (base, data = {}) => Object.freeze({ ...base, ...data });
3+
const createContext = (base, data = {}) =>
4+
Object.freeze({ ...base, ...data });
45

56
const withUser = (base, user) => createContext(base, { user });
67

@@ -39,5 +40,5 @@ console.log('Context 1:', getBalance(context1, 'ACC-002'), '\n');
3940
const context2 = withUser(context1, { name: 'Marcus', role: 'admin' });
4041
console.log('Context 2:', getBalance(context2, 'ACC-002'), '\n');
4142

42-
const context3 = withRequest(context2, 'req-' + Date.now());
43+
const context3 = withRequest(context2, `req-${Date.now()}`);
4344
console.log('Context 3:', getBalance(context3, 'ACC-002'), '\n');

0 commit comments

Comments
 (0)