Skip to content

Instantly share code, notes, and snippets.

@apla
Created June 4, 2015 13:32
Show Gist options
  • Save apla/71ffbda54a5ca7e6e0df to your computer and use it in GitHub Desktop.
Save apla/71ffbda54a5ca7e6e0df to your computer and use it in GitHub Desktop.

NOTE: this example require platform API with promise support (Promise, WinJS.Promise or $.defered)

  1. Open Inspector
  2. Paste test-app-preferences.js into Console
  3. Run fetchIncrementStore ("test-run-count") from Console

Value must increment regardless application restart

var fail = [];
var pass = 0;
var appp = plugins.appPreferences;
if (typeof Promise === "undefined") {
console.error ("this code snippet require Promise, WinJS.Promise or $.defered");
}
function fetchIncrementStore (keyName) {
var testRunCount;
appp.fetch (keyName).then (function (value) {
testRunCount = value || 0;
testRunCount++;
pass++;
}, function (err) {
console.error (err);
fail.push ('promise '+keyName+' failed');
}).then (function () {
appp.store (keyName, testRunCount)
}).then (function () {
console.info ("test run #"+testRunCount);
}, function (err) {
console.error (err);
});
}
fetchIncrementStore ("test-run-count");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment