 
     @components = {} # "name" -> { command: "", language: ''|null }.  lazy-loaded using load()
 
+  _updateComponents: (components) ->
+    names = Object.keys components
+    for name, comp of components
+      @components[name] = comp
+    @emit 'components-changed', names, @components
+
   load: (callback) ->
     componentsFromDirectory @options.componentdir, @options.config, (err, components) =>
       return callback err if err
-      for k,v of components
-        @components[k] = v
-      for k,v of componentsFromConfig @options.config
-        @components[k] = v
+      @_updateComponents components
+      @_updateComponents componentsFromConfig(@options.config)
       return callback null
 
   getSource: (name, callback) ->


    fs.writeFile filename, code, (err) =>
      return callback err if err
      @components[name] =
        language: language
        command: componentCommandForFile @options.config, filename
      return callback null

  componentCommand: (component, role, iips={}) ->

fs = require 'fs'
path = require 'path'
debug = require('debug')('msgflo:library')
EventEmitter = require('events').EventEmitter

common = require './common'

