Upgrade to ExtJS 4.0.7 - Released 10/19/2011
[extjs.git] / src / state / Manager.js
1 /*
2
3 This file is part of Ext JS 4
4
5 Copyright (c) 2011 Sencha Inc
6
7 Contact:  http://www.sencha.com/contact
8
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file.  Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
11
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
13
14 */
15 /**
16  * @class Ext.state.Manager
17  * This is the global state manager. By default all components that are "state aware" check this class
18  * for state information if you don't pass them a custom state provider. In order for this class
19  * to be useful, it must be initialized with a provider when your application initializes. Example usage:
20  <pre><code>
21 // in your initialization function
22 init : function(){
23    Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
24    var win = new Window(...);
25    win.restoreState();
26 }
27  </code></pre>
28  * This class passes on calls from components to the underlying {@link Ext.state.Provider} so that
29  * there is a common interface that can be used without needing to refer to a specific provider instance
30  * in every component.
31  * @singleton
32  * @docauthor Evan Trimboli <evan@sencha.com>
33  */
34 Ext.define('Ext.state.Manager', {
35     singleton: true,
36     requires: ['Ext.state.Provider'],
37     constructor: function() {
38         this.provider = Ext.create('Ext.state.Provider');
39     },
40     
41     
42     /**
43      * Configures the default state provider for your application
44      * @param {Ext.state.Provider} stateProvider The state provider to set
45      */
46     setProvider : function(stateProvider){
47         this.provider = stateProvider;
48     },
49
50     /**
51      * Returns the current value for a key
52      * @param {String} name The key name
53      * @param {Object} defaultValue The default value to return if the key lookup does not match
54      * @return {Object} The state data
55      */
56     get : function(key, defaultValue){
57         return this.provider.get(key, defaultValue);
58     },
59
60     /**
61      * Sets the value for a key
62      * @param {String} name The key name
63      * @param {Object} value The state data
64      */
65      set : function(key, value){
66         this.provider.set(key, value);
67     },
68
69     /**
70      * Clears a value from the state
71      * @param {String} name The key name
72      */
73     clear : function(key){
74         this.provider.clear(key);
75     },
76
77     /**
78      * Gets the currently configured state provider
79      * @return {Ext.state.Provider} The state provider
80      */
81     getProvider : function(){
82         return this.provider;
83     }
84 });