diff options
Diffstat (limited to 'src/apis.js')
| -rw-r--r-- | src/apis.js | 58 | 
1 files changed, 44 insertions, 14 deletions
| diff --git a/src/apis.js b/src/apis.js index 7aa9f0c2..bec54b8e 100644 --- a/src/apis.js +++ b/src/apis.js @@ -840,20 +840,22 @@ var angularFunction = {   * Hash of a:   *  string is string   *  number is number as string - *  object is either call $hashKey function on object or assign unique hashKey id. + *  object is either result of calling $$hashKey function on the object or uniquely generated id,  + *         that is also assigned to the $$hashKey property of the object.   *   * @param obj - * @returns {String} hash string such that the same input will have the same hash string + * @returns {String} hash string such that the same input will have the same hash string. + *         The resulting string key is in 'type:hashKey' format.   */  function hashKey(obj) {    var objType = typeof obj;    var key = obj;    if (objType == 'object') { -    if (typeof (key = obj.$hashKey) == 'function') { +    if (typeof (key = obj.$$hashKey) == 'function') {        // must invoke on object to keep the right this -      key = obj.$hashKey(); +      key = obj.$$hashKey();      } else if (key === undefined) { -      key = obj.$hashKey = nextUid(); +      key = obj.$$hashKey = nextUid();      }    }    return objType + ':' + key; @@ -868,13 +870,9 @@ HashMap.prototype = {     * Store key value pair     * @param key key to store can be any type     * @param value value to store can be any type -   * @returns old value if any     */    put: function(key, value) { -    var _key = hashKey(key); -    var oldValue = this[_key]; -    this[_key] = value; -    return oldValue; +    this[hashKey(key)] = value;    },    /** @@ -888,16 +886,48 @@ HashMap.prototype = {    /**     * Remove the key/value pair     * @param key -   * @returns value associated with key before it was removed     */    remove: function(key) { -    var _key = hashKey(key); -    var value = this[_key]; -    delete this[_key]; +    var value = this[key = hashKey(key)]; +    delete this[key];      return value;    }  }; +/** + * A map where multiple values can be added to the same key such that the form a queue. + * @returns {HashQueueMap} + */ +function HashQueueMap(){} +HashQueueMap.prototype = { +  /** +   * Same as array push, but using an array as the value for the hash +   */ +  push: function(key, value) { +    var array = this[key = hashKey(key)]; +    if (!array) { +      this[key] = [value]; +    } else { +      array.push(value); +    } +  }, + +  /** +   * Same as array shift, but using an array as the value for the hash +   */ +  shift: function(key) { +    var array = this[key = hashKey(key)]; +    if (array) { +      if (array.length == 1) { +        delete this[key]; +        return array[0]; +      } else { +        return array.shift(); +      } +    } +  } +}; +  function defineApi(dst, chain){    angular[dst] = angular[dst] || {};    forEach(chain, function(parent){ | 
