 
     @emit 'add', name
 
-    @ # chainable
+    return @ # chainable
 
   remove: (name) ->
     throw new Error "Port #{name} not defined" unless @ports[name]

# Ports collection classes for NoFlo components. These are
# used to hold a set of input or output ports of a component.
class Ports extends EventEmitter
  model: InPort
  constructor: (ports) ->
    super()
    @ports = {}
    return unless ports
    for name, options of ports

    delete @[name]
    @emit 'remove', name

    return @ # chainable

exports.InPorts = class InPorts extends Ports
  constructor: (ports) ->
    super ports, InPort

  on: (name, event, callback) ->
    throw new Error "Port #{name} not available" unless @ports[name]
    @ports[name].on event, callback
    return
  once: (name, event, callback) ->
    throw new Error "Port #{name} not available" unless @ports[name]
    @ports[name].once event, callback
    return

exports.OutPorts = class OutPorts extends Ports
  constructor: (ports) ->
    super ports, OutPort

  connect: (name, socketId) ->
    throw new Error "Port #{name} not available" unless @ports[name]
    @ports[name].connect socketId
    return
  beginGroup: (name, group, socketId) ->
    throw new Error "Port #{name} not available" unless @ports[name]
    @ports[name].beginGroup group, socketId
    return
  send: (name, data, socketId) ->
    throw new Error "Port #{name} not available" unless @ports[name]
    @ports[name].send data, socketId
    return
  endGroup: (name, socketId) ->
    throw new Error "Port #{name} not available" unless @ports[name]
    @ports[name].endGroup socketId
    return
  disconnect: (name, socketId) ->
    throw new Error "Port #{name} not available" unless @ports[name]
    @ports[name].disconnect socketId
    return

# Port name normalization:
# returns object containing keys name and index for ports names in
