Upgrade to ExtJS 4.0.7 - Released 10/19/2011
[extjs.git] / docs / source / WebStorage.html
index 31b7231..1fb9d40 100644 (file)
@@ -1,35 +1,48 @@
-<!DOCTYPE html><html><head><title>Sencha Documentation Project</title><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../prettify.css" type="text/css"><link rel="stylesheet" href="../prettify_sa.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script></head><body onload="prettyPrint()"><pre class="prettyprint"><pre><span id='Ext-data.proxy.WebStorage-method-constructor'><span id='Ext-data.proxy.WebStorage'>/**
-</span></span> * @author Ed Spencer
- * @class Ext.data.proxy.WebStorage
- * @extends Ext.data.proxy.Client
- * 
- * &lt;p&gt;WebStorageProxy is simply a superclass for the {@link Ext.data.proxy.LocalStorage localStorage} and 
- * {@link Ext.data.proxy.SessionStorage sessionStorage} proxies. It uses the new HTML5 key/value client-side storage 
- * objects to save {@link Ext.data.Model model instances} for offline use.&lt;/p&gt;
- * 
- * @constructor
- * Creates the proxy, throws an error if local storage is not supported in the current browser
- * @param {Object} config Optional config object
+<!DOCTYPE html>
+<html>
+<head>
+  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+  <title>The source code</title>
+  <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
+  <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
+  <style type="text/css">
+    .highlight { display: block; background-color: #ddd; }
+  </style>
+  <script type="text/javascript">
+    function highlight() {
+      document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
+    }
+  </script>
+</head>
+<body onload="prettyPrint(); highlight();">
+  <pre class="prettyprint lang-js"><span id='Ext-data-proxy-WebStorage'>/**
+</span> * @author Ed Spencer
+ *
+ * WebStorageProxy is simply a superclass for the {@link Ext.data.proxy.LocalStorage LocalStorage} and {@link
+ * Ext.data.proxy.SessionStorage SessionStorage} proxies. It uses the new HTML5 key/value client-side storage objects to
+ * save {@link Ext.data.Model model instances} for offline use.
+ * @private
  */
 Ext.define('Ext.data.proxy.WebStorage', {
     extend: 'Ext.data.proxy.Client',
     alternateClassName: 'Ext.data.WebStorageProxy',
-    
-<span id='Ext-data.proxy.WebStorage-cfg-id'>    /**
-</span>     * @cfg {String} id The unique ID used as the key in which all record data are stored in the local storage object
+
+<span id='Ext-data-proxy-WebStorage-cfg-id'>    /**
+</span>     * @cfg {String} id
+     * The unique ID used as the key in which all record data are stored in the local storage object.
      */
     id: undefined,
 
-<span id='Ext-data.proxy.WebStorage-method-constructor'>    /**
-</span>     * @ignore
+<span id='Ext-data-proxy-WebStorage-method-constructor'>    /**
+</span>     * Creates the proxy, throws an error if local storage is not supported in the current browser.
+     * @param {Object} config (optional) Config object.
      */
     constructor: function(config) {
         this.callParent(arguments);
-        
-<span id='Ext-data.proxy.WebStorage-property-cache'>        /**
-</span>         * Cached map of records already retrieved by this Proxy - ensures that the same instance is always retrieved
-         * @property cache
-         * @type Object
+
+<span id='Ext-data-proxy-WebStorage-property-cache'>        /**
+</span>         * @property {Object} cache
+         * Cached map of records already retrieved by this Proxy. Ensures that the same instance is always retrieved.
          */
         this.cache = {};
 
@@ -57,7 +70,7 @@ Ext.define('Ext.data.proxy.WebStorage', {
             length  = records.length,
             ids     = this.getIds(),
             id, record, i;
-        
+
         operation.setStarted();
 
         for (i = 0; i &lt; length; i++) {
@@ -92,11 +105,11 @@ Ext.define('Ext.data.proxy.WebStorage', {
             ids     = this.getIds(),
             length  = ids.length,
             i, recordData, record;
-        
+
         //read a single record
         if (operation.id) {
             record = this.getRecord(operation.id);
-            
+
             if (record) {
                 records.push(record);
                 operation.setSuccessful();
@@ -107,7 +120,7 @@ Ext.define('Ext.data.proxy.WebStorage', {
             }
             operation.setSuccessful();
         }
-        
+
         operation.setCompleted();
 
         operation.resultSet = Ext.create('Ext.data.ResultSet', {
@@ -133,7 +146,7 @@ Ext.define('Ext.data.proxy.WebStorage', {
         for (i = 0; i &lt; length; i++) {
             record = records[i];
             this.setRecord(record);
-            
+
             //we need to update the set of ids here because it's possible that a non-phantom record was added
             //to this proxy - in which case the record's id would never have been added via the normal 'create' call
             id = record.getId();
@@ -167,7 +180,7 @@ Ext.define('Ext.data.proxy.WebStorage', {
         }
 
         this.setIds(newIds);
-        
+
         operation.setCompleted();
         operation.setSuccessful();
 
@@ -176,9 +189,9 @@ Ext.define('Ext.data.proxy.WebStorage', {
         }
     },
 
-<span id='Ext-data.proxy.WebStorage-method-getRecord'>    /**
+<span id='Ext-data-proxy-WebStorage-method-getRecord'>    /**
 </span>     * @private
-     * Fetches a model instance from the Proxy by ID. Runs each field's decode function (if present) to decode the data
+     * Fetches a model instance from the Proxy by ID. Runs each field's decode function (if present) to decode the data.
      * @param {String} id The record's unique ID
      * @return {Ext.data.Model} The model instance
      */
@@ -207,14 +220,14 @@ Ext.define('Ext.data.proxy.WebStorage', {
 
             this.cache[id] = record;
         }
-        
+
         return this.cache[id];
     },
 
-<span id='Ext-data.proxy.WebStorage-method-setRecord'>    /**
-</span>     * Saves the given record in the Proxy. Runs each field's encode function (if present) to encode the data
+<span id='Ext-data-proxy-WebStorage-method-setRecord'>    /**
+</span>     * Saves the given record in the Proxy. Runs each field's encode function (if present) to encode the data.
      * @param {Ext.data.Model} record The model instance
-     * @param {String} id The id to save the record under (defaults to the value of the record's getId() function)
+     * @param {String} [id] The id to save the record under (defaults to the value of the record's getId() function)
      */
     setRecord: function(record, id) {
         if (id) {
@@ -245,25 +258,25 @@ Ext.define('Ext.data.proxy.WebStorage', {
 
         obj = me.getStorageObject();
         key = me.getRecordKey(id);
-        
+
         //keep the cache up to date
         me.cache[id] = record;
-        
+
         //iPad bug requires that we remove the item before setting it
         obj.removeItem(key);
         obj.setItem(key, Ext.encode(data));
     },
 
-<span id='Ext-data.proxy.WebStorage-method-removeRecord'>    /**
+<span id='Ext-data-proxy-WebStorage-method-removeRecord'>    /**
 </span>     * @private
      * Physically removes a given record from the local storage. Used internally by {@link #destroy}, which you should
      * use instead because it updates the list of currently-stored record ids
-     * @param {String|Number|Ext.data.Model} id The id of the record to remove, or an Ext.data.Model instance
+     * @param {String/Number/Ext.data.Model} id The id of the record to remove, or an Ext.data.Model instance
      */
     removeRecord: function(id, updateIds) {
         var me = this,
             ids;
-            
+
         if (id.isModel) {
             id = id.getId();
         }
@@ -277,11 +290,11 @@ Ext.define('Ext.data.proxy.WebStorage', {
         me.getStorageObject().removeItem(me.getRecordKey(id));
     },
 
-<span id='Ext-data.proxy.WebStorage-method-getRecordKey'>    /**
+<span id='Ext-data-proxy-WebStorage-method-getRecordKey'>    /**
 </span>     * @private
      * Given the id of a record, returns a unique string based on that id and the id of this proxy. This is used when
      * storing data in the local storage object and should prevent naming collisions.
-     * @param {String|Number|Ext.data.Model} id The record id, or a Model instance
+     * @param {String/Number/Ext.data.Model} id The record id, or a Model instance
      * @return {String} The unique key for this record
      */
     getRecordKey: function(id) {
@@ -292,7 +305,7 @@ Ext.define('Ext.data.proxy.WebStorage', {
         return Ext.String.format(&quot;{0}-{1}&quot;, this.id, id);
     },
 
-<span id='Ext-data.proxy.WebStorage-method-getRecordCounterKey'>    /**
+<span id='Ext-data-proxy-WebStorage-method-getRecordCounterKey'>    /**
 </span>     * @private
      * Returns the unique key used to store the current record counter for this proxy. This is used internally when
      * realizing models (creating them when they used to be phantoms), in order to give each model instance a unique id.
@@ -302,10 +315,10 @@ Ext.define('Ext.data.proxy.WebStorage', {
         return Ext.String.format(&quot;{0}-counter&quot;, this.id);
     },
 
-<span id='Ext-data.proxy.WebStorage-method-getIds'>    /**
+<span id='Ext-data-proxy-WebStorage-method-getIds'>    /**
 </span>     * @private
      * Returns the array of record IDs stored in this Proxy
-     * @return {Array} The record IDs. Each is cast as a Number
+     * @return {Number[]} The record IDs. Each is cast as a Number
      */
     getIds: function() {
         var ids    = (this.getStorageObject().getItem(this.id) || &quot;&quot;).split(&quot;,&quot;),
@@ -323,26 +336,26 @@ Ext.define('Ext.data.proxy.WebStorage', {
         return ids;
     },
 
-<span id='Ext-data.proxy.WebStorage-method-setIds'>    /**
+<span id='Ext-data-proxy-WebStorage-method-setIds'>    /**
 </span>     * @private
      * Saves the array of ids representing the set of all records in the Proxy
-     * @param {Array} ids The ids to set
+     * @param {Number[]} ids The ids to set
      */
     setIds: function(ids) {
         var obj = this.getStorageObject(),
             str = ids.join(&quot;,&quot;);
-        
+
         obj.removeItem(this.id);
-        
+
         if (!Ext.isEmpty(str)) {
             obj.setItem(this.id, str);
         }
     },
 
-<span id='Ext-data.proxy.WebStorage-method-getNextId'>    /**
+<span id='Ext-data-proxy-WebStorage-method-getNextId'>    /**
 </span>     * @private
-     * Returns the next numerical ID that can be used when realizing a model instance (see getRecordCounterKey). Increments
-     * the counter.
+     * Returns the next numerical ID that can be used when realizing a model instance (see getRecordCounterKey).
+     * Increments the counter.
      * @return {Number} The id
      */
     getNextId: function() {
@@ -350,19 +363,19 @@ Ext.define('Ext.data.proxy.WebStorage', {
             key  = this.getRecordCounterKey(),
             last = obj.getItem(key),
             ids, id;
-        
+
         if (last === null) {
             ids = this.getIds();
             last = ids[ids.length - 1] || 0;
         }
-        
+
         id = parseInt(last, 10) + 1;
         obj.setItem(key, id);
-        
+
         return id;
     },
 
-<span id='Ext-data.proxy.WebStorage-method-initialize'>    /**
+<span id='Ext-data-proxy-WebStorage-method-initialize'>    /**
 </span>     * @private
      * Sets up the Proxy by claiming the key in the storage object that corresponds to the unique id of this Proxy. Called
      * automatically by the constructor, this should not need to be called again unless {@link #clear} has been called.
@@ -372,8 +385,9 @@ Ext.define('Ext.data.proxy.WebStorage', {
         storageObject.setItem(this.id, storageObject.getItem(this.id) || &quot;&quot;);
     },
 
-<span id='Ext-data.proxy.WebStorage-method-clear'>    /**
-</span>     * Destroys all records stored in the proxy and removes all keys and values used to support the proxy from the storage object
+<span id='Ext-data-proxy-WebStorage-method-clear'>    /**
+</span>     * Destroys all records stored in the proxy and removes all keys and values used to support the proxy from the
+     * storage object.
      */
     clear: function() {
         var obj = this.getStorageObject(),
@@ -391,7 +405,7 @@ Ext.define('Ext.data.proxy.WebStorage', {
         obj.removeItem(this.id);
     },
 
-<span id='Ext-data.proxy.WebStorage-method-getStorageObject'>    /**
+<span id='Ext-data-proxy-WebStorage-method-getStorageObject'>    /**
 </span>     * @private
      * Abstract function which should return the storage object that data will be saved to. This must be implemented
      * in each subclass.
@@ -402,4 +416,6 @@ Ext.define('Ext.data.proxy.WebStorage', {
         Ext.Error.raise(&quot;The getStorageObject function has not been defined in your Ext.data.proxy.WebStorage subclass&quot;);
         //&lt;/debug&gt;
     }
-});</pre></pre></body></html>
\ No newline at end of file
+});</pre>
+</body>
+</html>