the name(s) of the event(s) to listen to
callback function of listener to attach
the index of the callback in the array of listeners for a particular event
Handles manually saving to file system, local storage, or adapter (such as indexeddb) This method utilizes loki configuration options (if provided) to determine which persistence method to use, or environment detection (if configuration was not provided).
If you are configured with autosave, you do not need to call this method yourself.
Serialize database to a string which can be loaded via {@link Loki#loadJSON}
Stringified representation of the loki database.
Adds a collection to the database.
name of collection to add
(optional) options to configure collection with.
a reference to the collection which was just added
autosaveClearFlags - resets dirty flags on all collections. Called from saveDatabase() after db is saved.
autosaveDirty - check whether any collections are 'dirty' meaning we need to save (entire) database
true if database has changed since last autosave, false if not.
autosaveDisable - stop the autosave interval timer.
autosaveEnable - begin a javascript interval to periodically save the database.
(Changes API) : clears all the changes in all collections.
Emits the close event. In autosave scenarios, if the database is dirty, this will save and disable timer. Does not actually destroy the db.
(Optional) if supplied will be registered with close event before emitting.
Allows reconfiguring database options
configuration options to apply to loki db object
(internal) true is passed when loki ctor is invoking
Copies 'this' database into a new Loki instance. Object references are shared to make lightweight.
apply or override collection level settings
nulls properties not safe for serialization.
Handles deleting a database from file system, local storage, or adapter (indexeddb) This method utilizes loki configuration options (if provided) to determine which persistence method to use, or environment detection (if configuration was not provided).
(Optional) user supplied async callback / error handler
Collection level utility function to deserializes a destructured collection.
destructured representation of collection to inflate
an array of documents to attach to collection.data.
Database level destructured JSON deserialization routine to minimize memory overhead. Internally, Loki supports destructuring via loki "serializationMethod' option and the optional LokiPartitioningAdapter class. It is also available if you wish to do your own structured persistence or data exchange.
destructured json or array to deserialize from
An object representation of the deserialized database, not yet applied to 'this' db or document array
emit(eventName, data) - emits a particular event with the option of passing optional parameters which are going to be processed by the callback provided signatures match (i.e. if passing emit(event, arg0, arg1) the listener should take two parameters)
the name of the event
optional object passed with the event
(Changes API) : takes all the changes stored in each collection and creates a single array for the entire database. If an array of names of collections is passed then only the included collections will be tracked.
array of changes
Retrieves reference to a collection by name.
name of collection to look up
Reference to collection in database by that name, or null if not found
Handles manually loading from file system, local storage, or adapter (such as indexeddb) This method utilizes loki configuration options (if provided) to determine which persistence method to use, or environment detection (if configuration was not provided). To avoid contention with any throttledSaves, we will drain the save queue first.
If you are configured with autosave, you do not need to call this method yourself.
Internal load logic, decoupled from throttling/contention logic
Inflates a loki database from a serialized JSON string
a serialized loki database string
Inflates a loki database from a JS object
a serialized loki database string
apply or override collection level settings
whether collection dirty flags will be preserved
on(eventName, listener) - adds a listener to the queue of callbacks associated to an event
the name(s) of the event(s) to listen to
callback function of listener to attach
the index of the callback in the array of listeners for a particular event
Removes a collection from the database.
name of collection to remove
removeListener() - removes the listener at position 'index' from the event 'eventName'
the name(s) of the event(s) which the listener is attached to
the listener callback function to remove from emitter
Renames an existing loki collection
name of collection to rename
new name of collection
reference to the newly renamed collection
Handles manually saving to file system, local storage, or adapter (such as indexeddb) This method utilizes loki configuration options (if provided) to determine which persistence method to use, or environment detection (if configuration was not provided).
If you are configured with autosave, you do not need to call this method yourself.
Internal save logic, decoupled from save throttling logic
Serialize database to a string which can be loaded via {@link Loki#loadJSON}
Stringified representation of the loki database.
(Changes API) - stringify changes for network transmission
string representation of the changes
Collection level utility method to serialize a collection in a 'destructured' format
A custom, restructured aggregation of independent serializations for a single collection.
Database level destructured JSON serialization routine to allow alternate serialization methods. Internally, Loki supports destructuring via loki "serializationMethod' option and the optional LokiPartitioningAdapter class. It is also available if you wish to do your own structured persistence or data exchange.
output format options for use externally to loki
(default: true) whether subitems are delimited or subarrays
override default delimiter
can be used to only output an individual collection or db (-1)
(default: false) whether db and each collection are separate
A custom, restructured aggregation of independent serializations.
serializeReplacer - used to prevent certain properties from being serialized
Wait for throttledSaves to complete and invoke your callback when drained or duration is met.
callback to fire when save queue is drained, it is passed a sucess parameter value
Generated using TypeDoc
on(eventName, listener) - adds a listener to the queue of callbacks associated to an event