Skip to content

@statesync/persistence


@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 enableCrossTab is true and a topic is provided; the channel name defaults to state-sync:<topic>

Type Parameters

Type ParameterDescription
TThe shape of the application state being persisted.

Parameters

ParameterTypeDescription
optionsPersistenceApplierOptions<T> & objectAll 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
});

Released under the MIT License.