Skip to content

Package @reatom/persist

@reatom/persist

Interfaces

PersistRecord

Defined in: persist/index.ts:26

Type Parameters

Snapshot

Snapshot = unknown

Properties

data

data: Snapshot

Defined in: persist/index.ts:27

id

id: number

Defined in: persist/index.ts:28

timestamp

timestamp: number

Defined in: persist/index.ts:30

to

to: number

Defined in: persist/index.ts:33

Time stamp after which the record is cleared.

version

version: string | number

Defined in: persist/index.ts:31


PersistStorage

Defined in: persist/index.ts:62

Type Parameters

Snapshot

Snapshot = unknown

Options

Options extends Rec = { }

Properties

cache

cache: PersistCache

Defined in: persist/index.ts:64

name

name: string

Defined in: persist/index.ts:63

Methods

clear()?

optional clear(options): void | Promise<void>

Defined in: persist/index.ts:72

Parameters
options

Options & object

Returns

void | Promise<void>

get()

get(options): PersistRecord<Snapshot> | Promise<PersistRecord<Snapshot> | null> | null

Defined in: persist/index.ts:65

Parameters
options

Options & object

Returns

PersistRecord<Snapshot> | Promise<PersistRecord<Snapshot> | null> | null

set()

set(options, rec): void | Promise<void>

Defined in: persist/index.ts:68

Parameters
options

Options & object

rec

PersistRecord<Snapshot>

Returns

void | Promise<void>

subscribe()?

optional subscribe(options, callback): Unsubscribe

Defined in: persist/index.ts:73

Parameters
options

Options & object

callback

(record) => void

Returns

Unsubscribe


PersistStorageCacheOption

Defined in: persist/index.ts:56

Properties

cache?

optional cache: Map<string, PersistRecord<unknown>>

Defined in: persist/index.ts:57


SyncPersistStorage

Defined in: persist/index.ts:80

Type Parameters

Snapshot

Snapshot = unknown

Options

Options extends Rec = { }

Properties

name

name: string

Defined in: persist/index.ts:84

Methods

clear()?

optional clear(options): void

Defined in: persist/index.ts:87

Parameters
options

Options & object

Returns

void

get()

get(options): PersistRecord<Snapshot> | null

Defined in: persist/index.ts:85

Parameters
options

Options & object

Returns

PersistRecord<Snapshot> | null

set()

set(options, rec): void

Defined in: persist/index.ts:86

Parameters
options

Options & object

rec

PersistRecord<Snapshot>

Returns

void

subscribe()?

optional subscribe(options, callback): Unsubscribe

Defined in: persist/index.ts:88

Parameters
options

Options & object

callback

(record) => void

Returns

Unsubscribe


WithPersist()

Defined in: persist/index.ts:152

Type Parameters

Snapshot

Snapshot = unknown

Options

Options extends Rec = { }

Call Signature

WithPersist<Target, Decode>(options): Ext<Target>

Defined in: persist/index.ts:154

Type Parameters
Target

Target extends AtomLike<any, any[], any>

Decode

Decode

Parameters
options

Options & WithPersistOptions<AtomState<Target>, Decode>

Returns

Ext<Target>

Call Signature

WithPersist<Target, Decode>(options): Ext<Target>

Defined in: persist/index.ts:158

Type Parameters
Target

Target extends AtomLike<any, any[], any>

Decode

Decode

Parameters
options

AtomState<Target> extends Snapshot ? object extends Options ? string : never | Options & WithPersistOptions<Snapshot & AtomState<Target>, Decode> : Options & WithPersistOptions<AtomState<Target>, Decode> & object

Returns

Ext<Target>

Properties

storageAtom

storageAtom: Atom<PersistStorage<Snapshot, { }>>

Defined in: persist/index.ts:170

Atom that holds the current storage instance, useful other environments, like SSR or tests to provide the storage instance to the user.


WithPersistOptions

Defined in: persist/index.ts:94

Type Parameters

State

State = unknown

Snapshot

Snapshot = unknown

Properties

fromSnapshot()?

optional fromSnapshot: (snapshot, state?) => State

Defined in: persist/index.ts:102

Custom snapshot deserializer.

Parameters
snapshot

Snapshot

state?

State

Returns

State

key

key: string

Defined in: persist/index.ts:96

Key of the storage record.

migration()?

optional migration: (persistRecord, version) => State

Defined in: persist/index.ts:111

A callback to call if the version of a stored snapshot is older than version option.

Parameters
persistRecord

PersistRecord<Snapshot>

version

string | number

Returns

State

schema?

optional schema: StandardSchemaV1<State, Snapshot>

Defined in: persist/index.ts:105

Schema to validate and transform the snapshot.

subscribe?

optional subscribe: boolean

Defined in: persist/index.ts:121

Determines whether the atom is updated on storage updates.

Default Value
true
time?

optional time: number

Defined in: persist/index.ts:129

Number of milliseconds from the snapshot creation time after which it will be deleted.

Default Value
MAX_SAFE_TIMEOUT
toSnapshot()?

optional toSnapshot: (state) => Snapshot

Defined in: persist/index.ts:99

Custom snapshot serializer.

Parameters
state

State

Returns

Snapshot

version?

optional version: string | number

Defined in: persist/index.ts:136

Version of the stored snapshot. Triggers migration.

Default Value
0

Type Aliases

PersistCache

PersistCache = Map<string, PersistRecord>

Defined in: persist/index.ts:60


WithRequiredPersistOptions

WithRequiredPersistOptions<State, Snapshot> = WithPersistOptions<State, Snapshot> & Shallow<Required<Pick<WithPersistOptions<State, Snapshot>, "fromSnapshot" | "toSnapshot">>>

Defined in: persist/index.ts:142

Type Parameters

State

State

Snapshot

Snapshot

Functions

assertPersistRecord()

assertPersistRecord(value, storage?): asserts value is PersistRecord<unknown>

Defined in: persist/index.ts:48

Parameters

value

unknown

storage?

string

Returns

asserts value is PersistRecord<unknown>


createMemStorage()

createMemStorage(__namedParameters): PersistStorage<unknown, { }> & object

Defined in: persist/index.ts:421

Parameters

__namedParameters
mutable?

boolean = true

name

string

snapshot?

Rec = {}

subscribe?

boolean = true

Returns

PersistStorage<unknown, { }> & object


isPersistRecord()

isPersistRecord(value): value is PersistRecord<unknown>

Defined in: persist/index.ts:36

Parameters

value

unknown

Returns

value is PersistRecord<unknown>


reatomPersist()

reatomPersist<Snapshot, Options>(storage): WithPersist<Snapshot, Options>

Defined in: persist/index.ts:173

Type Parameters

Snapshot

Snapshot = unknown

Options

Options extends Rec = { }

Parameters

storage

Omit<PersistStorage<Snapshot, Options & object>, "cache">

Returns

WithPersist<Snapshot, Options>