All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.vaadin.polymer.iron.widget.IronLocalstorage Maven / Gradle / Ivy

The newest version!
/*
 * This code was generated with Vaadin Web Component GWT API Generator, 
 * from iron-localstorage project by unknown author
 * that is licensed with http://polymer.github.io/LICENSE.txt license.
 */
package com.vaadin.polymer.iron.widget;

import com.vaadin.polymer.iron.*;

import com.vaadin.polymer.iron.widget.event.IronLocalstorageLoadEvent;
import com.vaadin.polymer.iron.widget.event.IronLocalstorageLoadEventHandler;

import com.vaadin.polymer.iron.widget.event.IronLocalstorageLoadEmptyEvent;
import com.vaadin.polymer.iron.widget.event.IronLocalstorageLoadEmptyEventHandler;

import com.vaadin.polymer.*;
import com.vaadin.polymer.elemental.*;
import com.vaadin.polymer.PolymerWidget;
import com.google.gwt.core.client.JsArray;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.core.client.JavaScriptObject;

/**
 * 

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
is resolved. Local storage will be blown away.
<iron-localstorage value="{{foo.bar}}" will cause data loss.

*/ public class IronLocalstorage extends PolymerWidget { /** * Default Constructor. */ public IronLocalstorage() { this(""); } /** * Constructor used by UIBinder to create widgets with content. */ public IronLocalstorage(String html) { super(IronLocalstorageElement.TAG, IronLocalstorageElement.SRC, html); } /** * Gets a handle to the Polymer object's underlying DOM element. */ public IronLocalstorageElement getPolymerElement() { return (IronLocalstorageElement) getElement(); } /** *

Value will not be saved automatically if true. You’ll have to do it manually with save()

* * JavaScript Info: * @property autoSaveDisabled * @type Boolean * */ public boolean getAutoSaveDisabled() { return getPolymerElement().getAutoSaveDisabled(); } /** *

Value will not be saved automatically if true. You’ll have to do it manually with save()

* * JavaScript Info: * @property autoSaveDisabled * @type Boolean * */ public void setAutoSaveDisabled(boolean value) { getPolymerElement().setAutoSaveDisabled(value); } /** *

If true: do not convert value to JSON on save/load

* * JavaScript Info: * @property useRaw * @type Boolean * */ public boolean getUseRaw() { return getPolymerElement().getUseRaw(); } /** *

If true: do not convert value to JSON on save/load

* * JavaScript Info: * @property useRaw * @type Boolean * */ public void setUseRaw(boolean value) { getPolymerElement().setUseRaw(value); } /** *

The data associated with this storage.
If set to null item will be deleted.

* * JavaScript Info: * @property value * @type * * */ public JavaScriptObject getValue() { return getPolymerElement().getValue(); } /** *

The data associated with this storage.
If set to null item will be deleted.

* * JavaScript Info: * @property value * @type * * */ public void setValue(JavaScriptObject value) { getPolymerElement().setValue(value); } /** *

Last error encountered while saving/loading items

* * JavaScript Info: * @property errorMessage * @type String * */ public String getErrorMessage() { return getPolymerElement().getErrorMessage(); } /** *

Last error encountered while saving/loading items

* * JavaScript Info: * @property errorMessage * @type String * */ public void setErrorMessage(String value) { getPolymerElement().setErrorMessage(value); } /** *

localStorage item key

* * JavaScript Info: * @property name * @type String * */ public String getName() { return getPolymerElement().getName(); } /** *

localStorage item key

* * JavaScript Info: * @property name * @type String * */ public void setName(String value) { getPolymerElement().setName(value); } // Needed in UIBinder /** *

The data associated with this storage.
If set to null item will be deleted.

* * JavaScript Info: * @attribute value * */ public void setValue(String value) { Polymer.property(this.getPolymerElement(), "value", value); } /** *

Loads the value again. Use if you modify
localStorage using DOM calls, and want to
keep this element in sync.

* * JavaScript Info: * @method reload * * */ public void reload() { getPolymerElement().reload(); } /** *

Saves the value to localStorage. Call to save if autoSaveDisabled is set.
If value is null or undefined, deletes localStorage.

* * JavaScript Info: * @method save * * */ public void save() { getPolymerElement().save(); } /** *

Fired when value loads from localStorage.

* * JavaScript Info: * @event iron-localstorage-load */ public HandlerRegistration addIronLocalstorageLoadHandler(IronLocalstorageLoadEventHandler handler) { return addDomHandler(handler, IronLocalstorageLoadEvent.TYPE); } /** *

Fired when loaded value does not exist.
Event handler can be used to initialize default value.

* * JavaScript Info: * @event iron-localstorage-load-empty */ public HandlerRegistration addIronLocalstorageLoadEmptyHandler(IronLocalstorageLoadEmptyEventHandler handler) { return addDomHandler(handler, IronLocalstorageLoadEmptyEvent.TYPE); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy