MemoryFeatureSelection
An in-memory FeatureSelection: the SDK's store and its fake in one
class, as MemorySettingsStore is. A host that wants the set kept
elsewhere supplies its own store instead.
This is a class exported by @mapcairn/core, checked against version 0.2.0.
Signature
import { MemoryFeatureSelection } from "@mapcairn/core";
class MemoryFeatureSelection implements FeatureSelection
Description
How to script it: pass limit to change how many references it holds, and
call replaceExternally to change the set from outside, as a host does when
it hydrates a saved set or restores one after a failed save. Its
getState and subscribe are arrow properties, so they work unbound.
A change tells the listeners that were subscribed when it began, so a
listener that an earlier one unsubscribes during the same change is still
told once. That is deliberate, as in the layer catalogue's store, and
useSyncExternalStore tolerates it. A listener that throws stops the
listeners after it, and its error leaves the call that changed the set.
Constructors
(constructor)
constructor(options?: MemoryFeatureSelectionOptions);
Constructs a new instance of the MemoryFeatureSelection class
options?(MemoryFeatureSelectionOptions)
Properties
getState
readonly getState: () => readonly FeatureRef[];
The references held, in order. The same array is returned until the set changes.
limit
readonly limit: number;
The most references it holds. An add or replace that would pass it changes nothing.
subscribe
readonly subscribe: (listener: () => void) => (() => void);
Calls the listener after the set changes. Returns the function that unsubscribes.
Methods
add
add(refs: readonly FeatureRef[]): void;
Appends the references it does not already hold. Changes nothing if that would pass the limit.
refs(readonly FeatureRef[])
clear
clear(): void;
Empties the set.
remove
remove(refs: readonly FeatureRef[]): void;
Drops the references that are held. Others are ignored.
refs(readonly FeatureRef[])
replace
replace(refs: readonly FeatureRef[]): void;
Makes the set exactly these references, without duplicates. Changes nothing if there are more than the limit.
refs(readonly FeatureRef[])
replaceExternally
replaceExternally(refs: readonly FeatureRef[]): void;
Makes the set exactly refs, without their duplicates and whatever the
limit, and tells the subscribers once if that changed it. For a test to
script a change from outside the ui.
refs(readonly FeatureRef[])
See also
Source: packages/core/src/fakes/MemoryFeatureSelection.ts:63