UNPKG

845 Btext/coffeescriptView Raw
1LinkedList = require "../collections/linkedList"
2
3module.exports = class Middleware extends LinkedList
4
5 ###
6 constructor
7 ###
8
9 constructor: (item, @director) ->
10
11 @listener = item.value
12 @channel = paths: item.cmpPath
13 @params = item.params
14 @tags = item.tags
15 @path = item.path # path string
16
17
18
19###
20 Wraps the chained callbacks in middleware
21###
22
23Middleware.wrap = (chain, pre, next, director) ->
24
25 for item in chain
26 current = new Middleware item, director
27 current.addPrevSibling prev, true if prev
28 prev = current
29
30 if typeof pre == 'function'
31 current.getFirstSibling().addPrevSibling new Middleware value: pre, params: {}, tags: {}, channel: paths: []
32
33 if typeof next == 'function'
34 current.addNextSibling new Middleware value: next, params: {}, tags: {}, channel: paths: []
35
36
37 current.getFirstSibling()
38