-
6 Jul 2009 4:29 AM #1
[TENT][3.0.0] Ext.state.StateManager#set/get and empty arrays / empty objects
[TENT][3.0.0] Ext.state.StateManager#set/get and empty arrays / empty objects
DESCRIPTION
If you save an empty object using StateManager#set and CookieProvider and retrieve the same object, you get back {"" : undefined} instead of {}. The same holds for empty arrays where you get back [""] instead of [].
TESTCASE
The following code fails with 3.0RC2
Code:// create cookies for testing if (Ext.state.Manager.get('empty-object') == null) { Ext.state.Manager.set('empty-object', {}); Ext.state.Manager.set('empty-array', []); location.reload(); }; var loadedObject = Ext.state.Manager.get('empty-object'); var ok = true; for (key in loadedObject) { ok = false; } console.log('empty object is loaded properly: ' + ok); var loadedArray = Ext.state.Manager.get('empty-array'); loadedArray = Ext.state.Manager.get('empty-array'); console.log('empty array is loaded properly: ' + (loadedArray.length == 0));
SOLUTION
In Ext.state.Provider#decodeValue check for empty values in the appropriate places. Here is my patch
Code:Ext.override(Ext.state.Provider, { decodeValue : function(cookie){ var re = /^(a|n|d|b|s|o)\:(.*)$/; var matches = re.exec(unescape(cookie)); if(!matches || !matches[1]) return; // non state cookie var type = matches[1]; var v = matches[2]; switch(type){ case "n": return parseFloat(v); case "d": return new Date(Date.parse(v)); case "b": return (v == "1"); case "a": var all = []; if (v != "") { var values = v.split("^"); for (var i = 0, len = values.length; i < len; i++) { all.push(this.decodeValue(values[i])); } } return all; case "o": var all = {}; if (v != "") { var values = v.split("^"); for (var i = 0, len = values.length; i < len; i++) { var kv = values[i].split("="); all[kv[0]] = this.decodeValue(kv[1]); } } return all; default: return v; } } })
-
6 Jul 2009 4:35 AM #2
you might want to highlight your changes in red for clarity.
additionally, you might want to retest against RC3 instead of RC2.
Sencha Docs / Ext 3.x - ( Docs | Examples )
Learning Center / Saki's Examples (for 2.x) / HOWTO - ( Report Bugs | Post Proper Code )
-
6 Jul 2009 4:42 AM #3
Thanks.
The changes are in red now.
I don't have the time to test against RC3, I just took a look at the source, though, and the code for decodeValue hasn't changed, so the problem presumably still exists.
-
6 Jul 2009 4:49 AM #4
Sencha Docs / Ext 3.x - ( Docs | Examples )
Learning Center / Saki's Examples (for 2.x) / HOWTO - ( Report Bugs | Post Proper Code )
-
21 Jul 2009 4:50 AM #5
Yes, this is indeed a bug and it's on the stable version of Ext 3. Should be commited to patch next versions...
-
21 Jul 2009 8:52 PM #6
Fixed in SVN.
Evan Trimboli
Sencha Developer
Twitter - @evantrimboli
Don't be afraid of the source code!
Thank you for reporting this bug. We will make it our priority to review this report.


Reply With Quote