UNPKG

1.73 kBJavaScriptView Raw
1(function() {
2 var LinkedList, Middleware,
3 __hasProp = Object.prototype.hasOwnProperty,
4 __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };
5
6 LinkedList = require("../collections/linkedList");
7
8 module.exports = Middleware = (function(_super) {
9
10 __extends(Middleware, _super);
11
12 /*
13 constructor
14 */
15
16 function Middleware(item, director) {
17 this.director = director;
18 this.listener = item.value;
19 this.channel = {
20 paths: item.cmpPath
21 };
22 this.params = item.params;
23 this.tags = item.tags;
24 this.path = item.path;
25 }
26
27 return Middleware;
28
29 })(LinkedList);
30
31 /*
32 Wraps the chained callbacks in middleware
33 */
34
35 Middleware.wrap = function(chain, pre, next, director) {
36 var current, item, prev, _i, _len;
37 for (_i = 0, _len = chain.length; _i < _len; _i++) {
38 item = chain[_i];
39 current = new Middleware(item, director);
40 if (prev) current.addPrevSibling(prev, true);
41 prev = current;
42 }
43 if (typeof pre === 'function') {
44 current.getFirstSibling().addPrevSibling(new Middleware({
45 value: pre,
46 params: {},
47 tags: {},
48 channel: {
49 paths: []
50 }
51 }));
52 }
53 if (typeof next === 'function') {
54 current.addNextSibling(new Middleware({
55 value: next,
56 params: {},
57 tags: {},
58 channel: {
59 paths: []
60 }
61 }));
62 }
63 return current.getFirstSibling();
64 };
65
66}).call(this);