You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wookie.apache.org by Ross Gardler <rg...@apache.org> on 2009/08/12 17:07:34 UTC

Data persistence in widgets

I just submitted my first patch for a project/task admin widget. It
doesn't do much just yet. Mainly because I don't know how to implement
data persistence.

In my next development iteration I wan to persist tasks in a local
file store (i.e. not on a remote task management app, that comes in a
later iteration). So, my question is, how do I persist a key/value
pair for an array of tasks so that next time the widget is retrieved
it will display the stored tasks?

-- 
Ross Gardler

OSS Watch - supporting open source in education and research
http://www.oss-watch.ac.uk

Re: Data persistence in widgets

Posted by Ross Gardler <rg...@apache.org>.
2009/8/12 Scott Wilson <sc...@gmail.com>:
> The answer

Perfect - thanks Scott, now I can start on my next iteration - but
probably after the weekend since I'm off to a muddy field to watch
bands with my son.

Ross

Re: Data persistence in widgets

Posted by Scott Wilson <sc...@gmail.com>.
The answer depends on the context where the widget is used:

- if the tasks are specific to the person who views the widget, then  
the API to use is W3C Widget Preferences API
- if the tasks are shared within a context, then the API to use is the  
Wave State API feature in Wookie

Preferences
=========
Preferences are very easy to work with.

To save a preference, in JavaScript call:

Widget.preferences.setItem("myitem", "myvalue");

To load a preference:

Widget.preferences.getItem("myitem");

Shared State
==========

Shared State is also pretty easy, but conceptually you have to be more  
careful about what you store as multiple widget instances will be  
accessing this data:

To save a state item, you need to submit a map:

wave.getState().submitDelta({"test":"testvalue"});

To get the item:

wave.getState().get("test");

To listen to changes to the widget state, you need to set a callback  
function:

wave.setStateCallback(myFunction);

Note that both Preferences and SharedState will only work in a  
container that supports the APIs, e.g. Wookie. However, you can sort  
of test Preferences in a browser if it supports HTML 5 LocalStorage by  
putting:

var Widget;
Widget.preferences = window.localstorage;

(This is because Widget Preferences uses the HTML 5 Storage definition)

-S

On 12 Aug 2009, at 16:07, Ross Gardler wrote:

> I just submitted my first patch for a project/task admin widget. It
> doesn't do much just yet. Mainly because I don't know how to implement
> data persistence.
>
> In my next development iteration I wan to persist tasks in a local
> file store (i.e. not on a remote task management app, that comes in a
> later iteration). So, my question is, how do I persist a key/value
> pair for an array of tasks so that next time the widget is retrieved
> it will display the stored tasks?
>
> -- 
> Ross Gardler
>
> OSS Watch - supporting open source in education and research
> http://www.oss-watch.ac.uk