Opened 10 years ago

Closed 9 years ago

#10618 closed enhancement (fixed)

[patch][cla] dojox.storage: New providers

Reported by: Jens Arps Owned by: Jens Arps
Priority: high Milestone: 1.6
Component: Storage/Flash Version: 1.4.0
Keywords: storage Cc:
Blocked By: Blocking:

Description

This patch adds the following providers for dojox.storage:

  • localStorage
  • MS IE userData behavior
  • Cookies

With these providers, there's an almost 100% coverage of browsers supported by dojox.storage without having to rely on third party plugins such as Flash or Gears.

  • localStorage addresses Firefox 3+, IE 8, Safari 4 (and the future, I guess)
  • userData behavior addresses IE 5+
  • Cookie storage is there to provide a fallback

A broad and reliable support of persistant storage mechanisms seems pretty important. To have it now, you'd have to use third party solutions such as Lawnchair or persist.js. It would be great if we had it built in with dojo.

I also edited the readme file and added an overview table of browsers and supported storage providers.

A test page including these providers is available here: http://jensarps.de/tests/dojo_tests/dojo-release-1.4.0-src/dojox/storage/tests/test_storage.html

NOTE: I added a patch for just the loacalStorage provider in December 2009 (http://bugs.dojotoolkit.org/ticket/10476). To ease things, this patch includes that provider as well.

Attachments (6)

storage.diff (21.6 KB) - added by Jens Arps 10 years ago.
Patch including the three new providers and changes to _common.js and README
Patch_clear_BehaviorStorageProvider.diff (526 bytes) - added by dmeunier 9 years ago.
Fix bug in clear function.
Patch_initialize_BehaviorStorageProvider.diff (613 bytes) - added by dmeunier 9 years ago.
we connect BehaviorStorageProvider? contructor to document.onreadystatechange so it is initialized before the parsing by dojo.parser
BehaviorStorageProvider.js.diff (6.1 KB) - added by Jens Arps 9 years ago.
CookieStorageProvider.js.diff (5.1 KB) - added by Jens Arps 9 years ago.
LocalStorageProvider.js.diff (5.6 KB) - added by Jens Arps 9 years ago.

Download all attachments as: .zip

Change History (18)

Changed 10 years ago by Jens Arps

Attachment: storage.diff added

Patch including the three new providers and changes to _common.js and README

comment:1 Changed 10 years ago by Adam Peller

Component: DojoxStorage/Flash
Owner: changed from Adam Peller to Shane O'Sullivan

comment:2 Changed 9 years ago by dylan

Can we get this reviewed and/or committed... looks like an awesome set of improvements!

comment:3 Changed 9 years ago by Shane O'Sullivan

I'll take a look at it this weekend

comment:4 Changed 9 years ago by brettz9

Hi... Any chance we could get action on this? This is really important I think... Otherwise, have to fallback to Flash or the like...Thanks!

comment:5 Changed 9 years ago by Shane O'Sullivan

I have some time free this weekend, I'll have a go at it.

comment:6 in reply to:  5 Changed 9 years ago by dmeunier

Hi,

I've detected one bug in BehaviorStorageProvider?, the function clear doesn't really clear the namespace I think you forgot to save the modification in the storage, see patch_clear_BehaviorStorageProvider.diff

I also think that we can add a little modification to the BehaviorStorageProvider? if we connect it to document.onreadystatechange it can be initialized before the parsing by dojo.parser. It is usefull for api which need to load some data before any widget creation or rendering. see Patch_initialize_BehaviorStorageProvider.

I hope my contribution will help you.

Changed 9 years ago by dmeunier

Fix bug in clear function.

Changed 9 years ago by dmeunier

we connect BehaviorStorageProvider? contructor to document.onreadystatechange so it is initialized before the parsing by dojo.parser

comment:7 Changed 9 years ago by dmeunier

Hi,

I think there is a little problem on HTML5 based localStorage. the "isAvailable" function tests if the "localStorage" object is present. Browsers who handle localStorage works fine but old browsers like IE6, Chrome 3, Safari 3 crashes when the localStorage object is tested.

I suggest to surround the test by a try and if we catch an error to return false.

isAvailable: function(){ /*Boolean*/
	try{
		localStorage;
	} catch (e){
		return false;
	}	
	return true;
},

comment:8 Changed 9 years ago by Adam Peller

just test for

typeof localStorage != "undefined"

comment:9 Changed 9 years ago by Jens Arps

I did some testing over the weekend, covering follwowing browsers:
OSX: Safari 5, latest WebKit, Chrome 5, latest Chromium, FF 3.6, latest Minefield
Win XP: Opera 10.6, IE 7 & 8
The Behavior provider is, of course, only tested in IE. I did not, however, test the providers on IE 6 and 9, and on mobile browsers. These are the changes/fixes I made to the providers:

  • CookieProvider:
    • fixed a bug where clear() would nuke all namespaces instead of just the specified one.
    • get() now returns the expected null instead of undefined if a key is not present.
  • BehaviorProvider:
    • fixed the above reported bug where clear() didn't update the internal keymap.
    • the store is now attached to the head, removing the dependency from addOnLoad inside of the provider
  • LocalStorageProvider:
    • added a typeof check in isAvailable.
    • put() now returns the message of an exception, if one is raised.

The following attachments are diffs against the 1.4.0. trunk.

Changed 9 years ago by Jens Arps

Changed 9 years ago by Jens Arps

Changed 9 years ago by Jens Arps

comment:10 Changed 9 years ago by dylan

Milestone: tbd1.6

comment:11 Changed 9 years ago by Jens Arps

Owner: changed from Shane O'Sullivan to Jens Arps
Status: newassigned

comment:12 Changed 9 years ago by Jens Arps

Resolution: fixed
Status: assignedclosed

(In [23350]) Adding the new storage providers for localStorage, MS IE userData behavior and Cookies, closes #10618

Note: See TracTickets for help on using tickets.