Manager.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /**
  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. }
  11. </code></pre>
  12. * This class passes on calls from components to the underlying {@link Ext.state.Provider} so that
  13. * there is a common interface that can be used without needing to refer to a specific provider instance
  14. * in every component.
  15. * @singleton
  16. * @docauthor Evan Trimboli <evan@sencha.com>
  17. */
  18. Ext.define('Ext.state.Manager', {
  19. singleton: true,
  20. requires: ['Ext.state.Provider'],
  21. constructor: function() {
  22. this.provider = new Ext.state.Provider();
  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. * Returns the current value for a key
  33. * @param {String} name The key name
  34. * @param {Object} defaultValue The default value to return if the key lookup does not match
  35. * @return {Object} The state data
  36. */
  37. get : function(key, defaultValue){
  38. return this.provider.get(key, defaultValue);
  39. },
  40. /**
  41. * Sets the value for a key
  42. * @param {String} name The key name
  43. * @param {Object} value The state data
  44. */
  45. set : function(key, value){
  46. this.provider.set(key, value);
  47. },
  48. /**
  49. * Clears a value from the state
  50. * @param {String} name The key name
  51. */
  52. clear : function(key){
  53. this.provider.clear(key);
  54. },
  55. /**
  56. * Gets the currently configured state provider
  57. * @return {Ext.state.Provider} The state provider
  58. */
  59. getProvider : function(){
  60. return this.provider;
  61. }
  62. });