loading
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
let pipelineBuilder = (functions, index = 0) => {

  if (functions.length == index) return (env) => { }; //Default handler

  let pipelineFunc = (environment) => functions[index](environment, pipelineBuilder(functions, index + 1));

  return pipelineFunc;
};

const middleware1 = (environment, next) => {

  console.log("middleware1", "\n", JSON.stringify(environment.Person), "\n");

  environment.Person.city = "Istanbul";

  next(environment);
};

const middleware2 = (environment, next) => {

  console.log("middleware2", "\n", JSON.stringify(environment.Person), "\n", "Person has a new field named city coming from middleware1\n");

  environment.Person.email = '[email protected]';

  next(environment);
};

const middleware3 = (environment, next) => {

  console.log("middleware3", "\n", JSON.stringify(environment.Person), "\n", "Person has a new field named email coming from middleware2\n");

  next(environment);
};


const pipelineInvoker = pipelineBuilder([middleware1, middleware2, middleware3]);

const person = {
  personId: 1,
  firstName: "kenan",
  lastName: "HANCER"
};

pipelineInvoker({
  Person: person
});
Babel Compiler v6.4.4 Copyright (c) 2014-2015 Sebastian McKenzie