# 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

```ts
import type { MessageStore } from "@mapcairn/core";
 
interface MessageStore
```

## Methods

### getInitialState

```ts
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

```ts
getState(): MessageStoreState;
```

The current state. The same object is returned until something changes.

### retry

```ts
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

```ts
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`)

## See also

- [`MessageStoreState`](https://docs.mapcairn.com/api/core/MessageStoreState.md)

Source: [packages/core/src/messages/messageStore.ts:32](https://github.com/MapCairn/mapcairn/blob/main/packages/core/src/messages/messageStore.ts#L32)
