htmlextjs4web-storagesession-state-provider

Sample Ext Js state provide?


Can anyone tell me sample of Ext JS provider, a specially if it intends to use any HTML 5 storage mechanism.

Thanks.


Solution

  • Ext.state.Provider is an abstract base class for state provider implementations. The current version of ExtJS has just one storage provider namely CookieProvider.

    You can create your on storage provider by inheriting the Provider class and implement HTML 5 storage mechanism. Here is a possible skeleton code:

    Ext.define('Ext.state.LocalStoreProvider', {
        extend: 'Ext.state.Provider',
    
        constructor : function(config){
            // 1. set default values
            // 2. Check if HTML5 storage is supported?
            // 3. load existing values
        },
    
    
        set : function(name, value){
            localStorage.setItem(name, value);
        },
    
        get : function(name,default) {
    
            var val = localStorage[name];
            if(val)
                return val;
            else
                return default; 
        },
    
        clear : function(name){
            localStorage.removeItem(name);  
        },
    
        decodeValue : function( val) {
    
            // Logic to decode an encoded data
        },
    
        encodeValue : function( val) {
    
            // Logic to encode a string data
        }
    
    });
    

    Note: This code is not complete, nor tested and requires more logic before being executed. This can be used as a starting point.