text: import { guidFor } from 'ember-metal/utils';
  import { sendEvent } from 'ember-metal/events';
  
  /*
    this.observerSet = {
      [senderGuid]: { // variable name: `keySet`
        [keyName]: listIndex
      }
    },
    this.observers = [
      {
        sender: obj,
        keyName: keyName,
        eventName: eventName,
        listeners: [
          [target, method, flags]
        ]
      },
      ...
    ]
  */
  export default ObserverSet;
  function ObserverSet() {
    this.clear();
  }
  
  
  ObserverSet.prototype.add = function(sender, keyName, eventName) {
    var observerSet = this.observerSet;
    var observers = this.observers;
    var senderGuid = guidFor(sender);
    var keySet = observerSet[senderGuid];
    var index;
  
    if (!keySet) {
      observerSet[senderGuid] = keySet = {};
    }
    index = keySet[keyName];
    if (index === undefined) {
      index = observers.push({
        sender: sender,
        keyName: keyName,
        eventName: eventName,
        listeners: []
      }) - 1;
      keySet[keyName] = index;
    }
    return observers[index].listeners;
  };
  
  ObserverSet.prototype.flush = function() {
    var observers = this.observers;
    var i, len, observer, sender;
    this.clear();
    for (i = 0, len = observers.length; i < len; ++i) {
      observer = observers[i];
      sender = observer.sender;
      if (sender.isDestroying || sender.isDestroyed) { continue; }
      sendEvent(sender, observer.eventName, [sender, observer.keyName], observer.listeners);
    }
  };
  
  ObserverSet.prototype.clear = function() {
    this.observerSet = {};
    this.observers = [];
  };
  
  