PolymerElements/iron-localstorage

Name: iron-localstorage

Owner: PolymerElements

Description: Access to localStorage

Created: 2015-04-27 23:38:21.0

Updated: 2018-04-19 16:52:03.0

Pushed: 2018-05-23 02:30:48.0

Homepage:

Size: 131

Language: HTML

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Build status

Demo and API docs

Changes in 2.0
<iron-localstorage>

Element access to Web Storage API (window.localStorage).

Keeps value property in sync with localStorage.

Value is saved as json by default.

Usage:

ls-sample will automatically save changes to its value.

-module id="ls-sample">
ron-localstorage name="my-app-storage"
value="{{cartoon}}"
on-iron-localstorage-load-empty="initializeDefaultCartoon"
/iron-localstorage>
m-module>

ipt>
lymer({
is: 'ls-sample',
properties: {
  cartoon: {
    type: Object
  }
},
// initializes default if nothing has been stored
initializeDefaultCartoon: function() {
  this.cartoon = {
    name: "Mickey",
    hasEars: true
  }
},
// use path set api to propagate changes to localstorage
makeModifications: function() {
  this.set('cartoon.name', "Minions");
  this.set('cartoon.hasEars', false);
}
;
ript>
Tech notes:

Element listens to StorageAPI storage event, and will reload upon receiving it.

Warning: do not bind value to sub-properties until Polymer bug 1550 is resolved. Local storage will be blown away. <iron-localstorage value="{{foo.bar}}" will cause data loss.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.