aboutsummaryrefslogtreecommitdiffstats
path: root/src/apis.js
diff options
context:
space:
mode:
authorMisko Hevery2011-04-18 16:33:30 -0700
committerMisko Hevery2011-06-08 15:21:31 -0700
commit8cad231bd219eddd518de8b8bd040d3f12f08d17 (patch)
tree75016fa6de683a877916f45a0fd06b1d0f312231 /src/apis.js
parent0e17ade959cc77369dc102d180e43be2af68505a (diff)
downloadangular.js-8cad231bd219eddd518de8b8bd040d3f12f08d17.tar.bz2
Refactor injector to have invoke method for speed reasons
Diffstat (limited to 'src/apis.js')
-rw-r--r--src/apis.js34
1 files changed, 31 insertions, 3 deletions
diff --git a/src/apis.js b/src/apis.js
index 11fa9838..1e1bcae1 100644
--- a/src/apis.js
+++ b/src/apis.js
@@ -807,6 +807,16 @@ var angularFunction = {
}
};
+/**
+ * Computes a hash of an 'obj'.
+ * Hash of a:
+ * string is string
+ * number is number as string
+ * object is either call $hashKey function on object or assign unique hashKey id.
+ *
+ * @param obj
+ * @returns {String} hash string such that the same input will have the same hash string
+ */
function hashKey(obj) {
var objType = typeof obj;
var key = obj;
@@ -821,17 +831,37 @@ function hashKey(obj) {
return objType + ':' + key;
}
+/**
+ * HashMap which can use objects as keys
+ */
function HashMap(){}
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;
},
+
+ /**
+ * @param key
+ * @returns the value for the key
+ */
get: function(key) {
return this[hashKey(key)];
},
+
+ /**
+ * 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];
@@ -852,8 +882,6 @@ defineApi('Array', [angularGlobal, angularCollection, angularArray]);
defineApi('Object', [angularGlobal, angularCollection, angularObject]);
defineApi('String', [angularGlobal, angularString]);
defineApi('Date', [angularGlobal, angularDate]);
-// TODO: enable and document this API
-//defineApi('HashMap', [HashMap]);
//IE bug
-angular['Date']['toString'] = angularDate['toString'];
+angular.Date.toString = angularDate.toString;
defineApi('Function', [angularGlobal, angularCollection, angularFunction]);