   class Promises extends Dictionary
 
   class Container
-    components: undefined
-    promises: undefined
-
-    constructor: (properties = {}) ->
-      @[key] = val for own key,val of properties
-
-      @components ?= new Components
-      @promises ?= new Promises
+
+    constructor: (properties = {}) ->
+      @components = new Components properties.components
+      @promises = new Promises properties.promises
+
+      @components.addListener "set", (event) =>
+        @promises.remove event.payload.key
+
+      @components.addListener "remove", (event) =>
+        @promises.remove event.payload.key
 
     createComponentPromise: (name) ->
       $.createPromise (resolve, reject) =>

    componentName: undefined
    cycles: undefined

    inspectCycles: ->
      mapFn = (cycle) -> "* #{cycle.join(" > ")}"
      @cycles.map(mapFn).join("\n")

    Object.defineProperty @prototype, "message", get: ->
      "Component '#{@componentName}' has cycles:\n" +
      @inspectCycles()

  class ComponentUndefined extends CustomError
    componentName: undefined

    Object.defineProperty @prototype, "message", get: ->
      "Component not defined: '#{@componentName}'"

  class Dictionary
    @definitions: undefined

    constructor: (properties = {}) ->
      @[key] = val for own key,val of properties
      @definitions ?= {}

    set: (name, value) ->
      @definitions[name] = value

    get: (name, value) ->
      @definitions[name]

    isDefined: (name) ->
      @definitions[name] != undefined

    isUndefined: (name) ->
      @definitions[name] == undefined

  class Components extends Dictionary



    constructor: (properties = {}) ->
      @[key] = val for own key,val of properties
      @name = @constructor.name
      @message = @getMessage()
      Error.captureStackTrace @, @constructor

    getMessage: -> @constructor.name

  class ComponentDependenciesUndefined extends CustomError
    componentName: undefined
    undefinedDependencies: undefined

    getMessage: ->
      "Component '#{@componentName}' " +
      "has undefined dependencies: [#{@undefinedDependencies}]"

