Skip to content

@gluonjs/core / packages/store/src / StoreAbortSignal

Interface: StoreAbortSignal ​

DOM-free subset accepted by async adapters, also compatible with AbortSignal.

Properties ​

aborted ​

readonly aborted: boolean


reason? ​

readonly optional reason?: unknown

Methods ​

addEventListener()? ​

optional addEventListener(type, listener, options?): void

Parameters ​

type ​

"abort"

listener ​

() => void

options? ​
once? ​

boolean

Returns ​

void

Example ​

Pass a DOM-free abort capability from an application or native adapter into Store persistence:

ts
import {
  createAsyncPersistencePlugin,
  createStoreManager,
  defineStore,
  type AsyncPersistenceLifecycle,
  type AsyncPersistencePlugin,
  type AsyncPersistencePluginOptions,
  type AsyncPersistenceStatus,
  type AsyncStorageLike,
  type StoreAbortSignal,
} from '@gluonjs/store';

declare function indexedDbGet(key: string, signal?: StoreAbortSignal): Promise<string | null>;
declare function indexedDbSet(key: string, value: string, signal?: StoreAbortSignal): Promise<void>;
const storage: AsyncStorageLike = {
  async getItem(key, signal) { return await indexedDbGet(key, signal); },
  async setItem(key, value, signal) { await indexedDbSet(key, value, signal); },
};
const signal: StoreAbortSignal | undefined = undefined;
const pluginOptions: AsyncPersistencePluginOptions = { storage, signal };
const persistence: AsyncPersistencePlugin = createAsyncPersistencePlugin(pluginOptions);
const manager = createStoreManager({ plugins: [persistence] });
const cart = manager.use(defineStore({ id: 'cart', state: () => ({ items: [] as string[] }), persist: true }));
const lifecycle: AsyncPersistenceLifecycle = persistence.lifecycle;
const status: AsyncPersistenceStatus = lifecycle.status;
await lifecycle.ready;
if (lifecycle.status === 'ready') console.log('bootstrap restored store', cart.items);

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