Skip to main content

MapStore

Something a page can read and listen to, in the shape of LayerCatalogue: getState returns the same object until the state changes, and subscribe calls the listener after each change, never from inside subscribe, and returns the function that stops it. No method uses this, so both can be passed on as they are, to React's useSyncExternalStore for one. In releases after 0.2.0, not in 0.2.0 or any earlier release.

This is an interface exported by @mapcairn/map, checked against version 0.2.0.

Signature​

import type { MapStore } from "@mapcairn/map";

interface MapStore<State>

Type parameters​

  • State

Methods​

getState​

getState(): State;

The state now.

subscribe​

subscribe(listener: () => void): () => void;

Calls listener after each change. Returns the function that stops it.

  • listener (() => void)

Source: packages/map/src/element/stores.ts:11