/**
 * Copyright 2013 Facebook, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * @providesModule CallbackRegistry
 */

"use strict";

var listenerBank = {};

/**
 * Stores "listeners" by `registrationName`/`id`. There should be at most one
 * "listener" per `registrationName/id` in the `listenerBank`.
 * Access listeners via `listenerBank[registrationName][id]`
 *
 * @constructor CallbackRegistry
 */
var CallbackRegistry = {

  /**
   * Stores `listener` at `listenerBank[registrationName][id]. Is idempotent.
   * @param {string} domID The id of the DOM node.
   * @param {string} registrationName The name of listener (`onClick` etc).
   * @param {Function} listener The callback to to store.
   */
  putListener: function(id, registrationName, listener) {
    var bankForRegistrationName =
      listenerBank[registrationName] || (listenerBank[registrationName] = {});
    bankForRegistrationName[id] = listener;
  },

  /**
   * @param {string} id.
   * @param {string} registrationName Name of registration (`onClick` etc).
   * @return {Function?} The Listener
   */
  getListener: function(id, registrationName) {
    var bankForRegistrationName = listenerBank[registrationName];
    return bankForRegistrationName && bankForRegistrationName[id];
  },

  /**
   * Deletes the listener from the registration bank.
   * @param {string} id
   * @param {string} registrationName (`onClick` etc).
   */
  deleteListener: function(id, registrationName) {
    var bankForRegistrationName = listenerBank[registrationName];
    if (bankForRegistrationName) {
      delete bankForRegistrationName[id];
    }
  },

  // This is needed for tests only. Do not use in real life
  __purge: function() {
    listenerBank = {};
  }
};

module.exports = CallbackRegistry;

@@ -619,24 +619,39 @@
 ackRegistry%0A
+ * @typechecks%0A
  */%0A%0A%22use st
@@ -799,17 +799,19 @@
 tionName
-/
+%60/%60
 id%60 in t
@@ -829,16 +829,19 @@
 rBank%60.%0A
+ *%0A
  * Acces
@@ -892,16 +892,17 @@
 me%5D%5Bid%5D%60
+.
 %0A *%0A * @
@@ -906,18 +906,12 @@
 * @c
-onstructor
+lass
  Cal
@@ -924,16 +924,29 @@
 egistry%0A
+ * @internal%0A
  */%0Avar 
@@ -1034,16 +1034,17 @@
 ame%5D%5Bid%5D
+%60
 . Is ide
@@ -1052,16 +1052,21 @@
 potent.%0A
+   *%0A
    * @pa
@@ -1082,20 +1082,13 @@
 ng%7D 
-domID The id
+id ID
  of 
@@ -1143,13 +1143,9 @@
 ame 
-The n
+N
 ame 
@@ -1157,16 +1157,21 @@
 stener (
+e.g. 
 %60onClick
@@ -1163,36 +1163,32 @@
  (e.g. %60onClick%60
- etc
 ).%0A   * @param %7B
@@ -1187,17 +1187,18 @@
 @param %7B
-F
+?f
 unction%7D
@@ -1223,19 +1223,16 @@
 back to 
-to 
 store.%0A 
@@ -1486,16 +1486,35 @@
 ring%7D id
+ ID of the DOM node
 .%0A   * @
@@ -1557,22 +1557,23 @@
  of 
-registration (
+listener (e.g. 
 %60onC
@@ -1573,28 +1573,24 @@
 g. %60onClick%60
- etc
 ).%0A   * @ret
@@ -1598,31 +1598,39 @@
 rn %7B
-F
+?f
 unction
-?
 %7D The 
-Listener
+stored callback.
 %0A   
@@ -1838,19 +1838,17 @@
 Deletes 
-the
+a
  listene
@@ -1877,16 +1877,21 @@
 n bank.%0A
+   *%0A
    * @pa
@@ -1905,16 +1905,36 @@
 ring%7D id
+ ID of the DOM node.
 %0A   * @p
@@ -1964,17 +1964,39 @@
 ionName 
-(
+Name of listener (e.g. 
 %60onClick
@@ -2000,12 +2000,8 @@
 ick%60
- etc
 ).%0A 
@@ -2214,17 +2214,23 @@
  %7D,%0A%0A  /
-/
+**%0A   *
  This is
@@ -2267,21 +2267,15 @@
  use
- in real life
+!%0A   */
 %0A  _
@@ -2322,16 +2322,17 @@
 %7B%7D;%0A  %7D%0A
+%0A
 %7D;%0A%0Amodu

Add @typechecks to `CallbackRegistry`