Skip to content

Provide storage abstractions #1

Description

@domenic

So web developers are used to localStorage. But we should be using Windows.Storage.ApplicationData. But of course that's an overwrought mess. WinningJS to the rescue!

Idea:

// Only localStorage examples shown, but the beauty is the same API in both cases.

var localStorage = require("WinningJS").storage.local;
var roamingStorage = require("WinningJS").storage.roaming;

// Idea #1: match ES6 map/dict methods
// Note: less powerful than ES6 map because you can't key by object 
localStorage.get("setting");
localStorage.has("setting");
localStorage.set("setting", arbitraryJsonableObject);
localStorage.delete("setting");
localStorage.empty(); // not a member of ES6 map or dict. async.

// Idea #2: match window.localStorage methods
// Note: less powerful than localStorage because you can't use indexer syntax.
localStorage.getItem("setting");
localStorage.setItem("setting", arbitraryJsonableObject); // note: more powerful than window.localStorage
localStorage.removeItem("setting");
localStorage.clear(); // async, unlike window.localStorage
// window.localStorage has no `has` method.

// http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.applicationdata.datachanged.aspx
roamingStorage.on("sync", function (ev) { });

Big missing piece: versioning!! Maybe instead of require("WinningJS").storage.local it should be require("WinningJS").storage.local.getVersion(1, upgradeHandler)?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions