Skip to content

Instantly share code, notes, and snippets.

@robdodson
Created July 10, 2015 21:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robdodson/fc83c0aba95b33e5ab43 to your computer and use it in GitHub Desktop.
Save robdodson/fc83c0aba95b33e5ab43 to your computer and use it in GitHub Desktop.
poly-storage
<!DOCTYPE html>
<html>
<head>
<!-- Web Components -->
<script src="bower_components/webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="bower_components/polymer/polymer.html">
<link rel="import" href="bower_components/iron-localstorage/iron-localstorage.html">
</head>
<body unresolved>
<template is="dom-bind" id="app">
<template is="dom-repeat" items="{{todos}}">
<div>{{item.title}}</div>
</template>
<iron-localstorage name="my-app-storage"
value="{{todos}}"
on-iron-localstorage-load-empty="onEmpty">
</iron-localstorage>
<input type="text" id="itemToAdd">
<button on-tap="addItem">Add Item</button>
</template>
<script>
var app = document.querySelector('#app');
app.addEventListener('dom-change', function() {
this.todos = [
{
title: 'foo'
},
{
title: 'bar'
},
{
title: 'baz'
}
];
console.log(this.get('todos'));
});
app.addItem = function() {
this.push('todos', {
title: this.$.itemToAdd.value
});
};
app.onEmpty = function() {
console.log('local storage is empty');
console.log(this.get('todos'));
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment