1. Bradley Workman
  2. js-util

Commits

bworkman  committed ab7b8c2

comment more code

  • Participants
  • Parent commits 4ed0572
  • Branches default

Comments (0)

Files changed (1)

File src/fox.util.js

View file
 /****h* fox.util/fox.util
 * DESCRIPTION
-*       A simple light-weight framework for production JavaScript.
+*       A simple light-weight library for production JavaScript.
 *
 * NOTES
-*       A major goal of this library is to make cross-browser 
+*       - A major goal of this library is to make cross-browser 
 * compatible, reviewed, production code.
 *
 * SEE ALSO
         *
         * TODO
         *       - rewrite this function for clarity
+        *       - rewrite this function to generate UUIDs according to spec
         *
         * SOURCE
         */
                 fox.util.cache = {
                         /****f* cache/read
                         * DESCRIPTION
-                        *       public -- produces a valid version 4 UUID
+                        *       public -- reads a value from client cache (localStorage)
                         *
                         * PARAMETERS
-                        *       none
+                        *       (string) key -- unique identifier used when 
+                        * writing the cache
                         *
                         * SIDE EFFECTS
-                        *       none
+                        *       if the cache has passed its end-of-life date,
+                        * it is deleted
                         *
                         * RESULT
-                        *       length 36 string
-                        *
-                        * TODO
-                        *       - rewrite this function for clarity
+                        *       null -- key was not found in cache or value 
+                        * has expired 
                         *
                         * SOURCE
                         */
 
                         /****f* cache/write
                         * DESCRIPTION
-                        *       public -- produces a valid version 4 UUID
+                        *       public -- stores a value in cache, possibly
+                        *  with an expiration (localStorage)
                         *
                         * PARAMETERS
-                        *       none
+                        *       (string) key - key to store the value under
+                        *       (object) val - value to store in the cache
+                        *       (Number) ttl - time to live, in seconds; cache is 
+                        * invalidated after this much time
                         *
                         * SIDE EFFECTS
-                        *       none
+                        *       adds to localStorage
                         *
                         * RESULT
-                        *       length 36 string
+                        *       returns key
                         *
-                        * TODO
-                        *       - rewrite this function for clarity
+                        * NOTES
+                        *       - relies on JSON.stringify; val should be 
+                        * stringable
                         *
                         * SOURCE
                         */
                         {
                                 var parcel = {value:val};
                                 if(!key) key = cf.util.uuid();
-                                if(typeof ttl === "Number")
+                                if(typeof ttl === "number")
                                 {
                                         var expires = new Date();
                                         expires.setTime(expires.getTime() + 1000 * ttl);
 
                         /****f* cache/erase
                         * DESCRIPTION
-                        *       public -- produces a valid version 4 UUID
+                        *       public -- deletes an item from cache
                         *
                         * PARAMETERS
-                        *       none
+                        *       (string) key - key to store the value under
                         *
                         * SIDE EFFECTS
-                        *       none
+                        *       removes item from localStorage identified by 'key'
                         *
                         * RESULT
-                        *       length 36 string
-                        *
-                        * TODO
-                        *       - rewrite this function for clarity
+                        *       none
                         *
                         * SOURCE
                         */