]> git.proxmox.com Git - extjs.git/blob - extjs/classic/classic/src/state/Manager.js
add extjs 6.0.1 sources
[extjs.git] / extjs / classic / classic / src / state / Manager.js
1 /**
2 * This is the global state manager. By default all components that are "state aware" check this class
3 * for state information if you don't pass them a custom state provider. In order for this class
4 * to be useful, it must be initialized with a provider when your application initializes. Example usage:
5 *
6 * // in your initialization function
7 * init: function() {
8 * Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
9 * }
10 *
11 * This class passes on calls from components to the underlying {@link Ext.state.Provider} so that
12 * there is a common interface that can be used without needing to refer to a specific provider instance
13 * in every component.
14 */
15 Ext.define('Ext.state.Manager', {
16 singleton: true,
17
18 requires: ['Ext.state.Provider'],
19
20 constructor: function() {
21 this.provider = new Ext.state.Provider();
22 },
23
24 /**
25 * Configures the default state provider for your application
26 * @param {Ext.state.Provider} stateProvider The state provider to set
27 */
28 setProvider: function (stateProvider) {
29 this.provider = stateProvider;
30 },
31
32 /**
33 * Returns the current value for a key
34 * @param {String} key The key name
35 * @param {Object} defaultValue The default value to return if the key lookup does not match
36 * @return {Object} The state data
37 */
38 get: function (key, defaultValue) {
39 return this.provider.get(key, defaultValue);
40 },
41
42 /**
43 * Sets the value for a key
44 * @param {String} key The key name
45 * @param {Object} value The state data
46 */
47 set: function (key, value) {
48 this.provider.set(key, value);
49 },
50
51 /**
52 * Clears a value from the state
53 * @param {String} key The key name
54 */
55 clear: function (key) {
56 this.provider.clear(key);
57 },
58
59 /**
60 * Gets the currently configured state provider
61 * @return {Ext.state.Provider} The state provider
62 */
63 getProvider: function () {
64 return this.provider;
65 }
66 });