Store
Public Class
Table of Contents
A store of records.
Signature
class Store<R extends BaseRecord = BaseRecord, Props = unknown> {}
References
Constructor
Public Constructor
Constructs a new instance of the Store
class
Parameters
Name | Description |
---|---|
|
|
References
Properties
allRecords
Public Property
Get an array of all values in the store.
Signature
allRecords: () => R[]
clear
Public Property
Removes all records from the store.
Signature
clear: () => void
createComputedCache
Public Property
Create a computed cache.
Parameters
Name | Description |
---|---|
| The name of the derivation cache. |
| A function used to derive the value of the cache. |
Signature
createComputedCache: <T, V extends R = R>(
name: string,
derive: (record: V) => T | undefined
) => ComputedCache<T, V>
References
createSelectedComputedCache
Public Property
Create a computed cache from a selector
Parameters
Name | Description |
---|---|
| The name of the derivation cache. |
| A function that returns a subset of the original shape |
| A function used to derive the value of the cache. |
Signature
createSelectedComputedCache: <T, J, V extends R = R>(
name: string,
selector: (record: V) => T | undefined,
derive: (input: T) => J | undefined
) => ComputedCache<J, V>
References
deserialize
Public Property
Opposite of serialize
. Replace the store's current records with records as defined by a simple JSON structure into the stores.
Parameters
Name | Description |
---|---|
| The JSON snapshot to deserialize. |
Signature
deserialize: (snapshot: StoreSnapshot<R>) => void
References
get
Public Property
Get the value of a store record by its id.
Parameters
Name | Description |
---|---|
| The id of the record to get. |
Signature
get: <K extends ID<R>>(id: K) => RecFromId<K> | undefined
References
has
Public Property
Get whether the record store has a id.
Parameters
Name | Description |
---|---|
| The id of the record to check. |
Signature
has: <K extends ID<R>>(id: K) => boolean
References
history
Public Readonly Property
An atom containing the store's history.
Signature
readonly history: Atom<number, RecordsDiff<R>>
References
listen
Public Property
Add a new listener to the store.
Parameters
Name | Description |
---|---|
| The listener to call when the store updates. |
Signature
listen: (listener: StoreListener<R>) => () => void
References
mergeRemoteChanges
Public Property
Merge changes from a remote source without triggering listeners.
Parameters
Name | Description |
---|---|
| A function that merges the external changes. |
Signature
mergeRemoteChanges: (fn: () => void) => void
onAfterChange
Public Property
A callback fired after each record's change.
Parameters
Name | Description |
---|---|
| The previous value, if any. |
| The next value. |
Signature
onAfterChange?: (prev: R, next: R) => void
onAfterCreate
Public Property
A callback fired after a record is created. Use this to perform related updates to other records in the store.
Parameters
Name | Description |
---|---|
| The record to be created |
Signature
onAfterCreate?: (record: R) => void
onAfterDelete
Public Property
A callback fired after a record is deleted.
Parameters
Name | Description |
---|---|
| The record that will be deleted. |
Signature
onAfterDelete?: (prev: R) => void
onBeforeDelete
Public Property
A callback fired before a record is deleted.
Parameters
Name | Description |
---|---|
| The record that will be deleted. |
Signature
onBeforeDelete?: (prev: R) => void
props
Public Readonly Property
Signature
readonly props: Props
put
Public Property
Add some records to the store. It's an error if they already exist.
Parameters
Name | Description |
---|---|
| The records to add. |
Signature
put: (records: R[], phaseOverride?: 'initialize') => void
query
Public Readonly Property
A StoreQueries instance for this store.
Signature
readonly query: StoreQueries<R>
References
remove
Public Property
Remove some records from the store via their ids.
Parameters
Name | Description |
---|---|
| The ids of the records to remove. |
Signature
remove: (ids: ID<R>[]) => void
References
schema
Public Readonly Property
Signature
readonly schema: StoreSchema<R, Props>
References
serialize
Public Property
Opposite of deserialize
. Creates a JSON payload from the record store.
Parameters
Name | Description |
---|---|
| A function to filter structs that do not satisfy the predicate. |
Signature
serialize: (filter?: ((record: R) => boolean) | undefined) => StoreSnapshot<R>
References
unsafeGetWithoutCapture
Public Property
Get the value of a store record by its id without updating its epoch.
Parameters
Name | Description |
---|---|
| The id of the record to get. |
Signature
unsafeGetWithoutCapture: <K extends ID<R>>(id: K) => RecFromId<K> | undefined
References
update
Public Property
Update a record. To update multiple records at once, use the update
method of the TypedStore
class.
Parameters
Name | Description |
---|---|
| The id of the record to update. |
| A function that updates the record. |
Signature
update: <K extends ID<R>>(
id: K,
updater: (record: RecFromId<K>) => RecFromId<K>
) => void
References
Methods
_flushHistory()
Public Method
Parameters
None
Returns
void
applyDiff()
Public Method
Parameters
Name | Description |
---|---|
|
|
(optional) |
|
Returns
void
References
extractingChanges()
Public Method
Parameters
Name | Description |
---|---|
|
|
Returns
RecordsDiff<R>
References
validate()
Public Method
Parameters
Name | Description |
---|---|
|
|
Returns
void