An interface for retrieving and managing persistently stored data.
The persistent store is a key-value store which is persisted between app restarts intended for small pieces of simple data. If your extension needs to store a large amount of data or individual documents, register a resource insteasd. Values are automatically namespaced by extension ID in order to prevent separate extensions from overwiting eachother's data.
The persistent store has two scopes, global
and local
.
The global store is backed up and synced accross devices when using the Sync add-on. It is intended for data which is not specific to an app installation. For example, internally, MindDrop stores a list of root level topic and tag IDs in the global store.
The local store is app specific and is not synced across devices. It is intended for app specific data. For example, internally, MindDrop stores the last opened view and sidebar width in the local store.
Hooks provide access to persistently stored data from inside React components. Unlike data accessed using static methods, hooks will cause the component to rerender when the data changes.
Returns an object containing all of the data stored by the extension in the global store.
useGlobalPersistentStore<T>(core: Core): T | undefined
Argument | Type | Description |
---|---|---|
core* | Core | A MindDrop core instance. |
Returns an object containing all of the data stored by the extension in the local store.
useLocalPersistentStore<T>(core: Core): T | undefined
Argument | Type | Description |
---|---|---|
core* | Core | A MindDrop core instance. |
Returns a value from the global store.
useGlobalPersistentValue<T>(core: Core, key: string, default?: T): T | undefined
Argument | Type | Description |
---|---|---|
core* | Core | A MindDrop core instance. |
key* | string | The key of the value to retrieve. |
default | any | The default value returned if the global store value does not exist. |
Returns a value from the local store.
useLocalPersistentValue<T>(core: Core, key: string, default?: T): T
Argument | Type | Description |
---|---|---|
core* | Core | A MindDrop core instance. |
default | any | The default value returned if the local store value does not exist. |
Returns an object containing all of the data stored by the extension in the global store.
PersistentStore.getGlobalStore<T>(core: Core): T
Argument | Type | Description |
---|---|---|
core* | Core | A MindDrop core instance. |
Returns an object containing all of the data stored by the extension in the local store.
PersistentStore.getLocalStore<T>(core: Core): T
Argument | Type | Description |
---|---|---|
core* | Core | A MindDrop core instance. |
Retrieves a value from the global store.
PersistentStore.getGlobalValue<T>(core: Core, key: string, default?: T): T
Argument | Type | Description |
---|---|---|
core* | Core | A MindDrop core instance. |
key* | string | The key of the value to retrieve. |
default | any | The default value returned if the global store value does not exist. |
Retrieves a value from the local store.
PersistentStore.getLocalValue<T>(core: Core, key: string, default: T): T
Argument | Type | Description |
---|---|---|
core* | Core | A MindDrop core instance. |
key* | string | The key of the value to retrieve. |
default | any | The default value returned if the local store value does not exist. |
Sets the extension's data in the global store and dispaches a persistent-store:update-global
event. Useful for initializing the extension's default global store data upon extension activation.
PersistentStore.setGlobalStore(core: Core, data: Record<string, any>): void
Argument | Type | Description |
---|---|---|
core* | Core | A MindDrop core instance. |
data* | Record<string, any> | An object containing the store data. The data values must be serializable into text. |
Sets the extension's data in the local store and dispaches a persistent-store:update-local
event. Useful for initializing the extension's default local store data upon extension activation.
PersistentStore.setLocalStore(core: Core, data: Record<string, any>): void
Argument | Type | Description |
---|---|---|
core* | Core | A MindDrop core instance. |
data* | Record<string, any> | An object containing the store data. The data values must be serializable into text. |
Sets a value in the global store and dispaches a persistent-store:update-global
event.
Supports FieldValue
mutations.
PersistentStore.setGlobalValue<T>(core: Core, key: string, value: T): void
Argument | Type | Description |
---|---|---|
core* | Core | A MindDrop core instance. |
key* | string | The key for which to set the value. |
value* | any | The data to set. Must be serializable into text. |
Sets a value in the local store and dispaches a persistent-store:update-local
event.
Supports FieldValue
mutations.
PersistentStore.setLocalValue<T>(core: Core, key: string, value: T): void
Argument | Type | Description |
---|---|---|
core* | Core | A MindDrop core instance. |
key* | string | The key for which to set the value. |
value* | any | The data to set. Must be serializable into text. |
Deletes a key and assotiated data from the global store. Dispatches a persistent-store:update-global
event.
PersistentStore.deleteGlobalValue(core: Core, key: string): void
Argument | Type | Description |
---|---|---|
core* | Core | A MindDrop core instance. |
key* | string | The key to delete. |
Deletes a key and assotiated data from the local store. Dispatches a persistent-store:update-local
event.
PersistentStore.deleteLocalValue(core: Core, key: string): void
Argument | Type | Description |
---|---|---|
core* | Core | A MindDrop core instance. |
key* | string | The key to delete. |
Permanently deletes all data added by the extension from the global store. Dispatches a persistent-store:update-global
event.
PersistentStore.deleteGlobalStore(core: Core): void
Argument | Type | Description |
---|---|---|
core* | Core | A MindDrop core instance. |
Permanently deletes all data added by the extension from the local store. Dispatches a persistent-store:update-local
event.
PersistentStore.deleteLocalStore(core: Core): void
Argument | Type | Description |
---|---|---|
core* | Core | A MindDrop core instance. |
Clears all data (including data added by other extensions) from the global store cache. This does not delete the persisted data.
Useful for forcefully refreshing the store from a storage adapter.
PersistentStore.clearGlobalCache(): void
Clears all data (including data added by other extensions) from the local store cache. This does not delete the persisted data.
Useful for forcefully refreshing the store from a storage adapter.
PersistentStore.clearLocalCache(): void
Adds persistent store specific event listeners. Equivalent to calling addEventListener
directly on core
, but provides more advanced type definitions.
PersistentStore.addEventListener(core: Core, event: PersistentStoreEvent, callback: EventListenerCallback): void
Argument | Type | Description |
---|---|---|
core* | Core | A MindDrop core instance. |
event* | PersistentStoreEvent | The event type to listen for. See the tag events section below for available events. |
callback* | EventListenerCallback | The callback fired when the event occurs. See the tag events section below for the data passed to the callback. |
Removes persistent store specific event listeners. Equivalent to calling removeEventListener
directly on core
, but provides more advanced type definitions.
Tags.removeEventListener(core: Core, event: PersistentStoreEvent, callback: EventListenerCallback): void
Argument | Type | Description |
---|---|---|
core* | Core | A MindDrop core instance. |
event* | PersistentStoreEvent | The event type for which to remove the event listener. |
callback* | EventListenerCallback | The callback of the event listener to remove. |
Name | Data | Description |
---|---|---|
persistent-store:create-global | PersistentStoreDocument | Dispatched when the global store document is created. |
persistent-store:create-local | PersistentStoreDocument | Dispatched when the local store document is created. |
persistent-store:update-global | UpdateGlobalStoreEventData | Dispatched when the global store is updated. |
persistent-store:update-local | UpdateLocalStoreEventData | Dispatched when the local store is updated. |
Property | Type | Description |
---|---|---|
before* | PersistentStoreDocument | Global store data before it was changed. |
after* | PersistentStoreDocument | Updated global store data. |
changes* | PersistentStoreChanges | The changes made to the global store data. See below for details. |
Property | Type | Description |
---|---|---|
before* | PersistentStoreDocument | Local store data before it was changed. |
after* | PersistentStoreDocument | Updated local store data. |
changes* | PersistentStoreChanges | The changes made to the local store data. See below for details. |
PersistentStoreDocument
An object containing the store document ID an a data
attribute consisting of key-value pairs namespaced by extension ID.
Example
globalStore = {
id: 'global-persistent-store',
data: {
app: {
topics: ['topic-1-id', 'topic-2-id'],
tags: ['tag-id'],
},
extensionId: {
foo: 'bar',
},
},
};
PersistentStoreChanges
An object describing the changes applied to the store document. Makes use of FieldValue
mutations to update the nested namespaced data. The values themselves can also consist of FieldValue
mutations.
Example
changes = {
data: FieldValue.objectUnion({
extensionId: FieldValue.objectUnion({ key: 'new-value' }),
}),
};