Skip to content

capptions/sc-storage

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sc-storage

Polymer 1.0 element for easy localStorage access

<sc-storage> is an element that exposes localStorage api's in a friendly way, especially for storing JSON

Getting started

Install with bower

First you need bower, see their site for details

bower install --save sc-storage

API

Method Name Functionality
get Get an object using parameter key
set Set an object using parameter key and value object
push Push to an array saved under parameter key with value object, alternatively passing unshift as true
shift Shift the first item from an array saved under paramter key and return it

How to use

  <sc-storage id="storage"></sc-storage>

Example usage

var shout = function (profile) {
  window.alert(profile.name.concat(' lives at ', profile.address!'));
};

// Store something
this.$.storage.set('profile', {
  name: 'superman',
  address: 'krypton'
});

// Retrieve something
var superman = this.$.storage.get('profile');
shout(superman);

// Push to an array
this.$.storage.push('profiles', {
  name: 'superman',
  address: 'krypton'
});

this.$.storage.push('profiles', {
  name: 'batman',
  address: 'gotham'
}, 'unshift');

// Retrieve and pop the first one from the array
var batman = this.$.storage.shift('profiles');
shout(batman);

// Clear the storage
this.$.storage.clear();

Contributions welcome, please create issues!

About

Polymer 1.0 element for easy localStorage access

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages