Live-storage API
Interface: LiveStorage
Extension of the Storage interface, with the addition of an event that is emitted when keys are added, values change or keys are removed, externally to the application.
Only changes effected by parts of the system other than the companion application itself trigger events on the storage object. This means that calling setItem, removeItem or clear on the storage object does not trigger any event.
Properties
readonly length
number
Number of key/value pairs currently present in the list associated with the object.
onchange
((this: LiveStorage, event: StorageChangeEvent) => any) or undefined
Event handler for change
events emitted by the storage.
Methods
addEventListener()
addEventListener(type: "change", listener: (this: LiveStorage, event: StorageChangeEvent) => any)
Returns: void
Add an event handler for change
events emitted by the storage.
Interface: StorageChangeEvent
Event that is emitted when a storage value is added, changed or removed.
Properties
readonly defaultPrevented
boolean
Set to true
when the default handling was prevented
readonly key
string or null
Name of the key when the value for a single key is set or when a single key is removed.
When all keys in the storage are removed at once, this value is null
.
readonly newValue
string or null
New value for a key for a single-key change, or null
when all keys in the storage are
removed at once.
readonly oldValue
string or null
Previous value for a key for a single-key change, or null
when the value for the key
is set for the first time, or when all keys in the storage are removed at once.
readonly target
EventTarget or undefined
Target of the event
readonly type
string
Type of the event
readonly url
string or undefined
A URL representing the component that triggered the change.
If present, this URL follows the following format: fitbit-app://$STORAGE_IDENTIFIER/$COMPONENT?app_uuid=$APP_UUID
For app cluster storage, the $STORAGE_IDENTIFIER
will be the
app cluster identifier followed by a .
and then the installation
source of the application ("gallery"
or "sideloaded"
).
The $COMPONENT
will either be companion.js
or settings.js
,
depending on which component caused the change.