Skip to content

Commit

Permalink
Merge pull request #58 from PolymerElements/gen-typescript-declarations
Browse files Browse the repository at this point in the history
Add TypeScript declarations to iron-localstorage.
  • Loading branch information
e111077 authored Feb 3, 2018
2 parents bf0385d + 006a65b commit 4526af0
Show file tree
Hide file tree
Showing 4 changed files with 1,062 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
bower_components*
bower-*.json
bower-*.json
node_modules
135 changes: 135 additions & 0 deletions iron-localstorage.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/**
* DO NOT EDIT
*
* This file was automatically generated by
* https://github.com/Polymer/gen-typescript-declarations
*
* To modify these typings, edit the source file(s):
* iron-localstorage.html
*/

/// <reference path="../polymer/types/polymer.d.ts" />

/**
* 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.
*
* <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**.
*/
interface IronLocalstorageElement extends Polymer.Element {

/**
* localStorage item key
*/
name: string|null|undefined;

/**
* The data associated with this storage.
* If set to null item will be deleted.
*/
value: any;

/**
* If true: do not convert value to JSON on save/load
*/
useRaw: boolean|null|undefined;

/**
* Value will not be saved automatically if true. You'll have to do it manually with `save()`
*/
autoSaveDisabled: boolean|null|undefined;

/**
* Last error encountered while saving/loading items
*/
errorMessage: string|null|undefined;

/**
* True if value has been loaded
*/
_loaded: boolean|null|undefined;
ready(): any;
attached(): any;
detached(): any;
_handleStorage(ev: any): any;
_trySaveValue(): any;
_debounceReload(): any;

/**
* Loads the value again. Use if you modify
* localStorage using DOM calls, and want to
* keep this element in sync.
*/
reload(): any;

/**
* loads value from local storage
*
* @param externalChange true if loading changes from a different window
*/
_load(externalChange?: boolean): any;

/**
* Saves the value to localStorage. Call to save if autoSaveDisabled is set.
* If `value` is null or undefined, deletes localStorage.
*/
save(): any;
}

interface HTMLElementTagNameMap {
"iron-localstorage": IronLocalstorageElement;
}
Loading

0 comments on commit 4526af0

Please sign in to comment.