StoreContext
A context object created by createStoreContext() that exposes the StoreOptions and collects eventual errors produced building the store.
export type StoreContext = { options: () => StoreOptions; hasErrors: () => boolean; errors: () => StoreError[]; addError: (error: StoreError) => void;};
Methods
༶ options()
Return Value: StoreOptions
This function throws an error if no options were provided to the context via createStoreContext().
༶ hasErrors()
Return Value: boolean
indicating if errors occurred building the store.
༶ errors()
Return Value: StoreError[] with any errors that occurred building the store.
༶ addError(error: StoreError)
Parameters:
error
: StoreError
Usage
Use createStoreContext() to create a StoreContext.
const config = await loadConfig();const context = createStoreContext(config.store);const builder = staticStoreBuilder(context);
When adding errors to the context you need to create a StoreError first. You can do this by calling createUnexpectedError()
with the exception.
import { createUnexpectedError } from './createUnexpectedError';
try { ...} catch (error) { context.addError(createUnexpectedError({ error }));}