MessageStore
The messages an interface speaks, as a store for any framework or none. No
method uses this, so each can be passed on as it is, as in React's
useSyncExternalStore(store.subscribe, store.getState, store.getInitialState).
This is an interface exported by @mapcairn/core, checked against version 0.2.0.
Signature
import type { MessageStore } from "@mapcairn/core";
interface MessageStore
Methods
getInitialState
getInitialState(): MessageStoreState;
The state before any load: Services.messages and no failure. It is what
a server renders, so pass it as the server snapshot: a store that has
since loaded another language still hydrates a server's markup without a
mismatch.
getState
getState(): MessageStoreState;
The current state. The same object is returned until something changes.
retry
retry(): void;
Loads the failed language again, even when the setting has not changed. It does nothing when none has failed or while that load is under way.
subscribe
subscribe(listener: () => void): () => void;
Calls the listener after each change of state. The first subscription
starts the store, and its listener may be called before subscribe
returns. Returns the function that unsubscribes. If that listener throws
then, the error leaves subscribe and the listener is not kept.
listener(() => void)