Make simple storage synchronous

RESOLVED FIXED

Status

Mozilla Labs
Jetpack Prototype
RESOLVED FIXED
9 years ago
9 years ago

People

(Reporter: adw, Assigned: adw)

Tracking

Details

Attachments

(1 attachment)

(Assignee)

Description

9 years ago
Let's do it.  Nobody's happy with async for what should be a simple API.  I talked with mconnor about it last night.  We'll provide avenues for Jetpack authors who need more heavy-duty storage solutions.  The async API is deprecated.

Here's how it works, quoting from source comments:

-----

Simple storage is really simple.  jetpack.storage.simple is a single, persistent JavaScript object available to each Jetpack feature.  For the most part this object is like any other JavaScript object, and a feature can set whatever properties it wants on it.  To manipulate its persistent data, a feature therefore need only use the various standard JavaScript functions and operators.  Each feature gets its own private storage.

To write the object to disk, you must call jetpack.storage.simple.sync().  To force the object to reload its data from disk, call jetpack.storage.simple.open(), although the data comes loaded automatically so you shouldn't have to worry about it.

Here's an example:

var myStorage = jetpack.storage.simple;
myStorage.fribblefrops = [1, 3, 3, 7];
myStorage.heimelfarbs = { bar: "baz" };
myStorage.sync();

And then later:

var myStorage = jetpack.storage.simple;
myStorage.fribblefrops.forEach(function (elt) console.log(elt));
var bar = myStorage.heimelfarbs.bar;

-----

We should investigate using Atul's catch-alls to obviate the need to manually sync the store.  Alternatively we could sync on a timer and on unload.
(Assignee)

Comment 1

9 years ago
Created attachment 387821 [details] [diff] [review]
patch

Now to figure out how to push to the repo...
(Assignee)

Comment 2

9 years ago
http://hg.mozilla.org/labs/jetpack/rev/af0389adbb5d
Status: ASSIGNED → RESOLVED
Last Resolved: 9 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.