SyncedMap

Holds an in-memory structure with potentially thousands of items.  Relies on PrefixTree for storing this structure to remoteStorage.

Summary
SyncedMapHolds an in-memory structure with potentially thousands of items.
Functions
getRetrieve one of the items from the in-memory store.
setStore an item into the in-memory store, under a key that identifies it uniquely.
removeRemove an item from the in-memory store, from under a key that identifies it uniquely.
getKeysReturns the keys of all items currently loaded into the in-memory store.
loadLoad the data into memory after a page refresh.

Functions

get

get: function(key)

Retrieve one of the items from the in-memory store.  Make sure to call load before calling this function.

Parameters

keystring, the identifier of the item to be retrieved.  Should not contain slashes.

Returns

The current value of the item identified by <key>, or undefined if the item doesn’t exist.  Will also return undefined if the item was not loaded yet.

set

set: function(key,
val)

Store an item into the in-memory store, under a key that identifies it uniquely.

Parameters

keystring, the identifier of the item to be retrieved.  Should not contain slashes.
valanything JSON-stringifiable (so objects and simple types are OK, but no ArrayBuffers and such).

remove

remove: function(key)

Remove an item from the in-memory store, from under a key that identifies it uniquely.

Parameters

keystring, the identifier of the item to be removed.  Should not contain slashes.

getKeys

getKeys: function()

Returns the keys of all items currently loaded into the in-memory store.

Returns

An Array of String, each string being one item key.

load

load: function(key)

Load the data into memory after a page refresh.  When the user connects their storage, data will come in and will be loaded automatically.  Also, data that was stored into the SyncedMap since the last page refresh will stay loaded automatically.  The only situation where the memory is flushed and you need to call SyncedMap.load, is when the user refreshes the page, or closes and reopens the tab, closes and reopens the browser, or turns the device off and on again.

Returns

A promise that fulfills when all items have been loaded from IndexedDB, through the BaseClient and the PrefixTree, into the SyncedMap (and therefore into memory).

get: function(key)
Retrieve one of the items from the in-memory store.
set: function(key,
val)
Store an item into the in-memory store, under a key that identifies it uniquely.
remove: function(key)
Remove an item from the in-memory store, from under a key that identifies it uniquely.
getKeys: function()
Returns the keys of all items currently loaded into the in-memory store.
load: function(key)
Load the data into memory after a page refresh.
Close