elf-sync-state
Version:
Syncs elf store state across tabs
19 lines (18 loc) • 660 B
TypeScript
import { Store, StoreValue } from '@ngneat/elf';
import { Observable } from 'rxjs';
export type PartialStore<S extends Store> = Partial<StoreValue<S>>;
export type SyncMessage<S extends Store> = {
type: 'REQUEST_STATE';
} | {
type: 'UPDATE_STATE';
state: PartialStore<S>;
};
interface Options<S extends Store> {
channel?: string;
source?: (store: S) => Observable<PartialStore<S>>;
preUpdate?: (event: MessageEvent<SyncMessage<S>>) => SyncMessage<S>;
runGuard?: () => boolean;
requestState?: boolean;
}
export declare function syncState<S extends Store>(store: S, options?: Options<S>): BroadcastChannel | undefined;
export {};