createMessageStore
Builds the message store for services, so a language loads once
however many parts of a page read it.
This is a function exported by @mapcairn/core, checked against version 0.2.0.
Signature
import { createMessageStore } from "@mapcairn/core";
function createMessageStore(services: MessageStoreServices): ConfigurableMessageStore;
Parameters
services(MessageStoreServices)
Returns
ConfigurableMessageStore
Remarks
Without Services.languages the catalogue is Services.messages,
always. With it, the language is resolved from the person's setting and
the browser's languages (see resolveLanguage) and then loaded.
Building the store does nothing: until its first subscription the state is
Services.messages and nothing is read, loaded or subscribed to, so it is
safe on a server and when a framework builds it twice. While anything
listens, it follows the settings and preferences stores, and it releases
both with the last listener. A later subscription picks up what changed
meanwhile, and does not repeat a load that is in flight, has succeeded, or
has failed with the setting and the browser's languages as they were.
Every render until a load finishes uses Services.messages or the last
catalogue that loaded, so a slow load never blanks the text. A load that
finishes after another language was asked for is dropped. One that fails
keeps the previous catalogue and warns, names the language in
MessageStoreState, and the language is requested again the
next time the setting or the browser's languages change, even to the same
tag, or when MessageStore is called.
A listener that throws stops the listeners after it, and its error leaves
the call that changed the state. A load it was being told about still runs.
When the error leaves the first subscribe, that listener is removed and
the services are released again, as if it had never subscribed.