Skip to content

Providers ​

A provider gives configuration documents to the wand. A provider can also save documents and send changes. All providers are in the entry magic-cursor-wand/providers.

Built-in providers ​

ProviderLoadSaveChanges
staticProvider(document)Returns the documentNoNo
localStorageProvider({ key })Reads the keyWrites the keyThe storage event from other tabs
httpProvider({ url })One GET requestPUT or POST, if you set savePolls with ETag, if you set pollMs
eventSourceProvider({ url })The first messageNoEach message
compositeProvider(name, providers)Merges the documents in sequenceSends the document to each writable providerMerges the changes

Slots and precedence ​

Each provider has one slot. When the result of a provider arrives, the wand puts it in the slot and merges all layers again. Thus a slow provider with low precedence cannot override a fast provider with high precedence.

The wand starts at once with the schema defaults and the config option. It does not wait for the providers. To wait for the providers before the first frame, set startAfter: 'ready'.

The promise wand.ready resolves after all providers settle. It never rejects. If a provider fails, the wand emits a provider error and continues.

Requests and cancellation ​

The httpProvider accepts one static headers object. The EventSource API cannot send headers, so the eventSourceProvider sends cookies with withCredentials.

The HTTP provider stops the polls while the page is not visible. When you call destroy, the wand stops all open requests.

Your own provider ​

A provider is an object with a name and a load function. The functions save and subscribe are optional. For a procedure, read Write a provider.