UNPKG

1.17 kBtext/coffeescriptView Raw
1noflo = require 'noflo'
2
3exports.getComponent = ->
4 c = new noflo.Component
5 c.description = 'Makes each data packet a stream of its own'
6 c.icon = 'pause'
7 c.forwardBrackets = {}
8 c.autoOrdering = false
9
10 c.inPorts.add 'in',
11 datatype: 'all'
12 description: 'Packet to be forward with disconnection'
13 c.outPorts.add 'out',
14 datatype: 'all'
15
16 brackets = {}
17 c.tearDown = (callback) ->
18 brackets = {}
19 c.process (input, output) ->
20 # Force auto-ordering to be off for this one
21 c.autoOrdering = false
22
23 data = input.get 'in'
24 brackets[input.scope] = [] unless brackets[input.scope]
25 if data.type is 'openBracket'
26 brackets[input.scope].push data.data
27 output.done()
28 return
29 if data.type is 'closeBracket'
30 brackets[input.scope].pop()
31 output.done()
32 return
33
34 return unless data.type is 'data'
35
36 for bracket in brackets[input.scope]
37 output.sendIP 'out', new noflo.IP 'openBracket', bracket
38 output.sendIP 'out', data
39 closes = brackets[input.scope].slice 0
40 closes.reverse()
41 for bracket in closes
42 output.sendIP 'out', new noflo.IP 'closeBracket', bracket
43
44 output.done()