diff options
| author | Misko Hevery | 2011-08-16 23:08:13 -0700 |
|---|---|---|
| committer | Igor Minar | 2011-10-11 10:53:04 -0700 |
| commit | 75f11f1fc46c35a28c0905f7316ea6779145e2fb (patch) | |
| tree | 2cd148b555552ee3985c31b953f7cf10a2a3ae38 /src/apis.js | |
| parent | e134a8335f5ee7d2e81034ed93f3e465cb14573f (diff) | |
| download | angular.js-75f11f1fc46c35a28c0905f7316ea6779145e2fb.tar.bz2 | |
feat(ng:repeat) collection items and DOM elements affinity / stability
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){ |
