Buffering Http State Provider

Hi all,

I've just finished coding and first tests of HttpProvider (Ext.ux.HttpProvider) that saves state data on a server not in cookies. It buffers changes for a configurable time and then saves them to a server with Ajax request. There is no client/server traffic if there are no changes.

this.addEvents(/** * @event readsuccess * Fires after state has been successfully received from server and restored * @param {HttpProvider} this */'readsuccess'/** * @event readfailure * Fires in the case of an error when attempting to read state from server * @param {HttpProvider} this */,'readfailure'/** * @event savesuccess * Fires after the state has been successfully saved to server * @param {HttpProvider} this */,'savesuccess'/** * @event savefailure * Fires in the case of an error when attempting to save state to the server * @param {HttpProvider} this */,'savefailure');

// {{{ /** * Initializes state from the passed state object or array. * This method can be called early during page load having the state Array/Object * retrieved from database by server. * @param {Array/Object} state State to initialize state manager with */,initState:function(state) { if(state instanceof Array) {Ext.each(state, function(item) {this.state[item.name] = this.decodeValue(item[this.paramNames.value]); }, this); } else {this.state = state ? state : {}; } } // eo function initState // }}} // {{{ /** * Sets the passed state variable name to the passed value and queues the change * @param {String} name Name of the state variable * @param {Mixed} value Value of the state variable */,set:function(name, value) { if(!name) { return; }

Very cool stuff, I may start experimenting with it too at some point.
One way to get around the the initial state issue I can think of is to have use a callback function with the initial state load. The typical app would then have most of its init code in this callback instead of in onReady.

Well, I have already solved the initial state problem. First, state system doesn't need to run in onReady block as it doesn't need any DOM. Therefore, I generate the initial state very early in the page generation process, I create code for creation and initialization of the state manager and I output it in the header in <script> tag. See one post above.

This way the state is available even before the body is loaded and w/o any extra client server round trip.

Your custom Provider looks very good, but i still don't know in detail what it does.

I also encountered the initial state problem while writing my own Provider. But in my project it does not seem to work the way you solved it (to set the initial setting at the start of the page). I think its because my page gets rendered into another page and the head of that page is already done (maybe i should use a delay-function after requesting the data from the server). How do you generate your initial state on top of your page? (inside the {})

Yeah , when i use a php-script to fetch the gridSettings from the DB i don't need an Ajax-Request cause the DB is requested (from the server-side) while the page gets rendered. And i can call the initState-Methode of my Provider right after i ordered Ext to use my Provider. All code is executed synchronously this way, which means i do not have to wait for an Ajax-Response.