# @npm-polymer/iron-localstorage

> Provides access to local storage

Latest version **2.0.0** (published 2017-06-03) · http://polymer.github.io/LICENSE.txt license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @npm-polymer/iron-localstorage
pnpm add @npm-polymer/iron-localstorage
yarn add @npm-polymer/iron-localstorage
bun add @npm-polymer/iron-localstorage
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2017-06-03 |
| First published | 2017-06-03 |
| Weekly downloads | 0 |
| License | http://polymer.github.io/LICENSE.txt |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 11 |
| Maintainers | npm-polymer |
| Keywords | web-component, polymer, storage |

## Links

- npm: https://www.npmjs.com/package/@npm-polymer/iron-localstorage
- Repository: https://github.com/PolymerElements/iron-localstorage
- Homepage: https://github.com/PolymerElements/iron-localstorage/
- Issues: https://github.com/PolymerElements/iron-localstorage/issues
- npm.io page: https://npm.io/package/@npm-polymer/iron-localstorage

## Dependencies (1)

- [@npm-polymer/polymer](https://npm.io/package/@npm-polymer/polymer.md) 2.0.1

## Alternatives

- [localforage](https://npm.io/package/localforage.md) — 6.2M weekly downloads
- [localforage-observable](https://npm.io/package/localforage-observable.md) — 30.8K weekly downloads
- [@y/y](https://npm.io/package/@y/y.md) — 30.1K weekly downloads
- [@metaobjectsdev/render](https://npm.io/package/@metaobjectsdev/render.md) — 3.5K weekly downloads
- [@ledgerhq/coin-algorand](https://npm.io/package/@ledgerhq/coin-algorand.md) — 1.1K weekly downloads

## Recent versions

- 2.0.0 (latest) — 2017-06-03

## README

<!---

This README is automatically generated from the comments in these files:
iron-localstorage.html

Edit those files, and our readme bot will duplicate them over here!
Edit this file, and the bot will squash your changes :)

The bot does some handling of markdown. Please file a bug if it does the wrong
thing! https://github.com/PolymerLabs/tedium/issues

-->

[![Build status](https://travis-ci.org/PolymerElements/iron-localstorage.svg?branch=master)](https://travis-ci.org/PolymerElements/iron-localstorage)

_[Demo and API docs](https://elements.polymer-project.org/elements/iron-localstorage)_

## Changes in 2.0
* ⚠️ This element is now deprecated ⚠️

## &lt;iron-localstorage&gt;

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.

```html
<dom-module id="ls-sample">
  <iron-localstorage name="my-app-storage"
    value="{{cartoon}}"
    on-iron-localstorage-load-empty="initializeDefaultCartoon"
  ></iron-localstorage>
</dom-module>

<script>
  Polymer({
    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);
    }
  });
</script>
```

### Tech notes:

* `value.*` is observed, and saved on modifications. You must use
  path change notification methods such as `set()` to modify value
  for changes to be observed.


* Set `auto-save-disabled` to prevent automatic saving.


* Value is saved as JSON by default.


* To delete a key, set value to null



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

__Warning__: do not bind value to sub-properties until Polymer
[bug 1550](https://github.com/Polymer/polymer/issues/1550)
is resolved. Local storage will be blown away.
`<iron-localstorage value="{{foo.bar}}"` will cause __data loss__.

---
_Source: https://npm.io/package/@npm-polymer/iron-localstorage · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
