Skip to main content

ElementSaveController

Purpose

Save the state of the attribute(s) of an element to LocalStorage, and restore it, at will.

Actions

ActionPurpose
saveSave the state of the element's specified attributes to LocalStorage
restoreRestore the element to its previous state from LocalStorage
clearClear any saved state regarding this element from LocalStorage

Targets

TargetPurposeDefault
elementThe element to persist state from, if not the controller root element. Particularly useful if you need toThe controller root element

Classes

ClassPurposeDefault
---

Values

ValueTypeDescriptionDefault
idStringThe unique ID of this element on the page. This combined with the current URL will be used as a key to store the value in LocalStorage. This allows multiple elements on the same page to all save.The ID of the controller root element, or throw an error an ID is not found and this is not specified
attributesStringA space separated set of DOM element attribute names, or attribute paths that Lodash.get accepts. I.e. dataset.foo, className-
restoreOnLoadBooleanWhether the controller should try to restore any previous state when the controller connectstrue

Events

EventWhenDispatched onevent.detail
element-save:clearedWhen the saved state is cleared, by the clear actionEither elementTarget or the controller root element-
element-save:save:successWhen the element saves successfullyEither elementTarget or the controller root element-
element-save:restore:successWhen the element restores values successfullyEither elementTarget or the controller root element-
element-save:restore:emptyWhen a restore is triggered, but there is nothing in LocalStorage to restoreEither elementTarget or the controller root element-

Side Effects

None

How to Use