@statesync/persistence / createPersistenceApplierWithDefaults
Function: createPersistenceApplierWithDefaults()
ts
function createPersistenceApplierWithDefaults<T>(options): DisposablePersistenceApplier<T>;Defined in: persistence/src/persistence-applier.ts:657
Creates a DisposablePersistenceApplier with sensible defaults pre-configured.
Defaults applied:
- Throttling:
debounceMs: 100,maxWaitMs: 2000(if not provided) - Cross-tab sync: Enabled when
enableCrossTabistrueand atopicis provided; the channel name defaults tostate-sync:<topic>
Type Parameters
| Type Parameter | Description |
|---|---|
T | The shape of the application state being persisted. |
Parameters
| Parameter | Type | Description |
|---|---|---|
options | PersistenceApplierOptions<T> & object | All standard PersistenceApplierOptions plus: - topic -- optional topic string used to derive the BroadcastChannel name - enableCrossTab -- if true and topic is set, cross-tab sync is enabled |
Returns
DisposablePersistenceApplier<T>
A disposable persistence applier configured with defaults.
Example
typescript
const applier = createPersistenceApplierWithDefaults({
storage: createLocalStorageBackend({ key: 'my-state' }),
applier: innerApplier,
topic: 'settings', // Used for cross-tab channel name
});