Created
July 10, 2015 21:19
-
-
Save robdodson/fc83c0aba95b33e5ab43 to your computer and use it in GitHub Desktop.
poly-storage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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