StateManager.js
上传用户:dawnssy
上传日期:2022-08-06
资源大小:9345k
文件大小:2k
源码类别:

JavaScript

开发平台:

JavaScript

  1. /*!  * Ext JS Library 3.1.0  * Copyright(c) 2006-2009 Ext JS, LLC  * licensing@extjs.com  * http://www.extjs.com/license  */ /**
  2.  * @class Ext.state.Manager
  3.  * This is the global state manager. By default all components that are "state aware" check this class
  4.  * for state information if you don't pass them a custom state provider. In order for this class
  5.  * to be useful, it must be initialized with a provider when your application initializes. Example usage:
  6.  <pre><code>
  7. // in your initialization function
  8. init : function(){
  9.    Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
  10.    var win = new Window(...);
  11.    win.restoreState();
  12. }
  13.  </code></pre>
  14.  * @singleton
  15.  */
  16. Ext.state.Manager = function(){
  17.     var provider = new Ext.state.Provider();
  18.     return {
  19.         /**
  20.          * Configures the default state provider for your application
  21.          * @param {Provider} stateProvider The state provider to set
  22.          */
  23.         setProvider : function(stateProvider){
  24.             provider = stateProvider;
  25.         },
  26.         /**
  27.          * Returns the current value for a key
  28.          * @param {String} name The key name
  29.          * @param {Mixed} defaultValue The default value to return if the key lookup does not match
  30.          * @return {Mixed} The state data
  31.          */
  32.         get : function(key, defaultValue){
  33.             return provider.get(key, defaultValue);
  34.         },
  35.         /**
  36.          * Sets the value for a key
  37.          * @param {String} name The key name
  38.          * @param {Mixed} value The state data
  39.          */
  40.          set : function(key, value){
  41.             provider.set(key, value);
  42.         },
  43.         /**
  44.          * Clears a value from the state
  45.          * @param {String} name The key name
  46.          */
  47.         clear : function(key){
  48.             provider.clear(key);
  49.         },
  50.         /**
  51.          * Gets the currently configured state provider
  52.          * @return {Provider} The state provider
  53.          */
  54.         getProvider : function(){
  55.             return provider;
  56.         }
  57.     };
  58. }();