New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tidy persisted settings #59

Closed
neocotic opened this Issue Jan 27, 2012 · 4 comments

Comments

Projects
None yet
1 participant
@neocotic
Member

neocotic commented Jan 27, 2012

Group settings in to objects so that localStorage is cleaner and easier to read.

Option tags don't necessarily have to change but deprecating some might be beneficial going forward.

Use the new store.modify method to easily change properties of objects in localStorage without multiple/distributed getters and setters.

Example:

store.modify 'toolbar', (toolbar) ->
  toolbar.close = yes                # Previously toolbarPopupClose
  toolbar.key   = 'PREDEFINED.00001' # Previously toolbarTemplateKey
  toolbar.style = no                 # Previously toolbarTemplateDetails
  toolbar.popup = yes                # Previously toolbarPopup & !toolbarTemplate
@neocotic

This comment has been minimized.

Show comment
Hide comment
@neocotic

neocotic Jan 30, 2012

Member

This appears to be implemented fine. All that remains is testing the version update.

Member

neocotic commented Jan 30, 2012

This appears to be implemented fine. All that remains is testing the version update.

@neocotic

This comment has been minimized.

Show comment
Hide comment
@neocotic

neocotic Feb 6, 2012

Member

Here's a good JavaScript snippet to test version updates;

(function () {
  var __test__ = window.__test__ = {};
  __test__.backup = function () {
    var obj = {}, prop;
    for (prop in localStorage) {
      if (localStorage.hasOwnProperty(prop)) {
        obj[prop] = localStorage[prop];
      }
    }
    return encodeURIComponent(JSON.stringify(obj));
  };
  __test__.clear = function () {
    var prop;
    for (prop in localStorage) {
      if (localStorage.hasOwnProperty(prop)) {
        delete localStorage[prop];
      }
    }
  };
  __test__.restore = function (str) {
    var obj, prop;
    obj = JSON.parse(decodeURIComponent(str));
    for (prop in obj) {
      if (obj.hasOwnProperty(prop)) {
        localStorage[prop] = obj[prop];
      }
    }
  };
}());
  1. Execute snippet in the consoles of the background pages for both the old and new versions
  2. Run __test__.backup() in the old version's console and copy the output
  3. Run __test__clear() in the new version's console
  4. Run __test__restore(PASTE) in the new version's console (where PASTE is the output copied from step 2)
  5. Reload the new version to see the changes
Member

neocotic commented Feb 6, 2012

Here's a good JavaScript snippet to test version updates;

(function () {
  var __test__ = window.__test__ = {};
  __test__.backup = function () {
    var obj = {}, prop;
    for (prop in localStorage) {
      if (localStorage.hasOwnProperty(prop)) {
        obj[prop] = localStorage[prop];
      }
    }
    return encodeURIComponent(JSON.stringify(obj));
  };
  __test__.clear = function () {
    var prop;
    for (prop in localStorage) {
      if (localStorage.hasOwnProperty(prop)) {
        delete localStorage[prop];
      }
    }
  };
  __test__.restore = function (str) {
    var obj, prop;
    obj = JSON.parse(decodeURIComponent(str));
    for (prop in obj) {
      if (obj.hasOwnProperty(prop)) {
        localStorage[prop] = obj[prop];
      }
    }
  };
}());
  1. Execute snippet in the consoles of the background pages for both the old and new versions
  2. Run __test__.backup() in the old version's console and copy the output
  3. Run __test__clear() in the new version's console
  4. Run __test__restore(PASTE) in the new version's console (where PASTE is the output copied from step 2)
  5. Reload the new version to see the changes
@neocotic

This comment has been minimized.

Show comment
Hide comment
@neocotic

neocotic Feb 13, 2012

Member

Tested this and fixed a few bugs but now I'm very happy with the results.

Member

neocotic commented Feb 13, 2012

Tested this and fixed a few bugs but now I'm very happy with the results.

@neocotic neocotic closed this Feb 13, 2012

@neocotic

This comment has been minimized.

Show comment
Hide comment
@neocotic

neocotic Feb 14, 2012

Member

Just noting that the test functionality used here has been permanently added to the store API for use while testing and debugging (clear already existed).

Member

neocotic commented Feb 14, 2012

Just noting that the test functionality used here has been permanently added to the store API for use while testing and debugging (clear already existed).

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