Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
noflo = require 'noflo' | ||
|
||
class SendByGroup extends noflo.Component | ||
description: 'Send packet held in "data" when receiving | ||
matching set of groups in "in"' | ||
icon: 'share-sign' | ||
|
||
constructor: -> | ||
@data = {} | ||
@ungrouped = null | ||
@dataGroups = [] | ||
@inGroups = [] | ||
|
||
@inPorts = | ||
in: new noflo.Port 'bang' | ||
data: new noflo.Port 'all' | ||
|
||
@outPorts = | ||
out: new noflo.ArrayPort 'all' | ||
|
||
@inPorts.data.on 'begingroup', (group) => | ||
@dataGroups.push group | ||
@inPorts.data.on 'data', (data) => | ||
unless @dataGroups.length | ||
@ungrouped = data | ||
return | ||
@data[@groupId(@dataGroups)] = data | ||
@inPorts.data.on 'endgroup', => | ||
@dataGroups.pop() | ||
|
||
@inPorts.in.on 'begingroup', (group) => | ||
@inGroups.push group | ||
@inPorts.in.on 'data', (data) => | ||
unless @dataGroups.length | ||
@send @ungrouped if @ungrouped isnt null | ||
return | ||
id = @groupId @inGroups | ||
unless @data[@groupId] | ||
return | ||
@send @data[id] | ||
@inPorts.in.on 'endgroup', => | ||
@inGroups.pop() | ||
@inPorts.in.on 'disconnect', => | ||
@outPorts.out.disconnect() | ||
|
||
groupId: (groups) -> | ||
groups.join ':' | ||
|
||
send: (data) -> | ||
for group in @inGroups | ||
@outPorts.out.beginGroup group | ||
@outPorts.out.send data | ||
for group in @inGroups | ||
@outPorts.out.endGroup() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters