FeatureSelection
The set of features a person has picked, kept wherever the host likes: in
memory, on a server or in its own state. Optional on Services: a host that
supplies none offers no selection, and the ui must not require it.
This is an interface exported by @mapcairn/core, checked against version 0.2.0.
Signature
import type { FeatureSelection } from "@mapcairn/core";
interface FeatureSelection
Description
The port is synchronous so that useSyncExternalStore can read it, which
needs a snapshot of stable identity, so it has no loading or failed state. A
store that saves somewhere slow keeps a local copy, writes behind it and
calls its subscribers when the copy changes, when it hydrates, or when a
save fails and it restores the copy.
Rules for every implementation:
getState()returns the same array until a change, in selection order.getStateandsubscribework when taken off the object, as React reads them.- A duplicate is ignored, within a call and against what is already held.
- A call that changes the set tells every subscriber once. A call that changes nothing tells none.
- A call that would take the total past
limitchanges nothing, so a batch is refused whole. A refusal is silent and the methods return nothing, so a caller who needs to tell a refused batch from one of duplicates comparesgetState()before and after. - A store may hold more than
limitreferences, for example when it hydrates a longer list. It shows them all and refuses every addition, and removing is always allowed. - No method throws, provided its input is well typed (every reference an object with both ids) and every listener returns without throwing.
Properties
limit
readonly limit: number;
The most references the set holds.
Methods
add
add(refs: readonly FeatureRef[]): void;
Appends the references that are not yet selected, in order.
refs(readonly FeatureRef[])
clear
clear(): void;
Empties the set.
getState
getState(): readonly FeatureRef[];
The selected references in selection order. It is also the server snapshot.
remove
remove(refs: readonly FeatureRef[]): void;
Removes the references that are selected, keeping the order of the rest.
refs(readonly FeatureRef[])
replace
replace(refs: readonly FeatureRef[]): void;
Makes the set exactly refs, in that order, without their duplicates.
Refused whole when the result would pass limit. The same members in
another order are a change.
refs(readonly FeatureRef[])
subscribe
subscribe(listener: () => void): () => void;
Calls listener after each change and returns how to stop.
listener(() => void)