Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Fetching contributors…
Cannot retrieve contributors at this time
57 lines (45 sloc) 1.63 KB
noflo = require "noflo"
class GroupByObjectKey extends noflo.Component
constructor: ->
@data = []
@key = null
@inPorts =
in: new noflo.Port()
key: new noflo.Port()
@outPorts =
out: new noflo.Port() "connect", =>
@data = [] "begingroup", (group) =>
@outPorts.out.beginGroup group "data", (data) =>
return @getKey data if @key
@data.push data "endgroup", =>
@outPorts.out.endGroup() "disconnect", =>
unless @data.length
# Data already sent
# No key, data will be sent when we get it
return unless @key
# Otherwise send data we have an disconnect
@getKey data for data in @data
@inPorts.key.on "data", (data) =>
@key = data
@inPorts.key.on "disconnect", =>
return unless @data.length
@getKey data for data in @data
getKey: (data) ->
throw new Error "Key not defined" unless @key
throw new Error "Data is not an object" unless typeof data is "object"
group = data[@key]
unless typeof data[@key] is "string"
group = "undefined"
@outPorts.out.beginGroup group
@outPorts.out.send data
exports.getComponent = -> new GroupByObjectKey
Jump to Line
Something went wrong with that request. Please try again.