Skip to content

Documentation / @etherfold/browser / hostIndexerInThisSharedWorker

Function: hostIndexerInThisSharedWorker() ​

hostIndexerInThisSharedWorker<ABI, ProcessResultType, ProcessorConfig>(spec): IndexerHost<ABI, ProcessResultType, ProcessorConfig>

Defined in: packages/browser/src/host/sharedWorker.ts:175

RUN THE INDEXER HERE, in the shared worker this is called from, for every tab that connects to it. The whole of what an app's entry point does.

ts
// indexer.worker.ts -- the same file, whichever shape an app chose
import {createBrowserStateStore, hostIndexerInThisSharedWorker} from '@etherfold/browser';
import {EntityEventProcessor} from '@etherfold/processor-entities';
import {openForWriting} from '@etherfold/state-store';
import {processor, source, provider} from './my-app.js';

hostIndexerInThisSharedWorker({
  createState: async (context, {signal}) =>
    openForWriting(await createBrowserStateStore(processor.entities), {signal}),
  createProcessor: (store) => new EntityEventProcessor(store, processor),
  provider,
  source,
});

The SPEC is the dedicated helper's spec, unchanged, and that is the point: the processor crosses as an IMPORT and never as a message, and the store is opened for WRITING here, which is what makes this host the writer and every tab a reader. Only the helper's name differs, and all it does differently is where it gets its wires.

The provider and the settings may be left out here and handed over by the tabs instead (connectToIndexerHost(access, {provider, settings})), as for the dedicated helper. With SEVERAL tabs each handing over a provider, the host folds through the first attached tab's and moves to the next one's when that tab goes away, rather than failing every request; with none left, it retries as it does when a provider is down (NoTabProviderError). See oneEndpointOverEveryClient.

Type Parameters ​

ABI ​

ABI extends Abi

ProcessResultType ​

ProcessResultType

ProcessorConfig ​

ProcessorConfig = undefined

Parameters ​

spec ​

HostedIndexerSpec<ABI, ProcessResultType, ProcessorConfig>

Returns ​

IndexerHost<ABI, ProcessResultType, ProcessorConfig>