Skip to content

@gluonjs/core / packages/store/src / PersistenceChannel

Interface: PersistenceChannel ​

Methods ​

addEventListener() ​

addEventListener(listener): void

Parameters ​

listener ​

(message) => void

Returns ​

void


close()? ​

optional close(): void

Returns ​

void


postMessage() ​

postMessage(message): void

Parameters ​

message ​

unknown

Returns ​

void


removeEventListener() ​

removeEventListener(listener): void

Parameters ​

listener ​

(message) => void

Returns ​

void

Example ​

Connect cross-tab messages to the persistence synchronization boundary:

ts
import { createBroadcastChannelFactory, createIndexedDbStorage, createLocalStorageAdapter, createMemoryStorage, createSessionStorageAdapter, createWebStorageAdapter, type IndexedDbFactory, type IndexedDbStorageOptions, type PersistenceChannel, type PersistenceChannelFactory, type PersistenceLifecycle, type PersistenceStatus, type PersistMergePolicy } from '@gluonjs/store';
const memory = createMemoryStorage({ draft: '{\"version\":1,\"state\":{}}' });
const local = createLocalStorageAdapter(memory);
const session = createSessionStorageAdapter(memory);
const web = createWebStorageAdapter('local', memory);
const channel: PersistenceChannel = { postMessage() {}, addEventListener() {}, removeEventListener() {} };
const channels: PersistenceChannelFactory = { create: () => channel };
const status: PersistenceStatus = 'ready';
const lifecycle: PersistenceLifecycle | undefined = undefined;
const merge: PersistMergePolicy<{ value: number }> = 'server-wins';
const factory: IndexedDbFactory | undefined = undefined;
const indexedDbOptions: IndexedDbStorageOptions = { database: 'shop', store: 'state', factory };
const indexed = factory ? createIndexedDbStorage(indexedDbOptions) : undefined;
const browserChannels = typeof BroadcastChannel === 'undefined' ? channels : createBroadcastChannelFactory();
console.log(local, session, web, indexed, browserChannels, status, lifecycle, merge);

Version-matched documentation. Examples are checked against the public package contracts.