electrum-field module handles state associated with form fields and is
Manipulating field states
A field can have multiple states associated with it:
- A state describing whether the field is enabled or read-only.
- A state describing the position of the cursor or the selection.
Each state is represented as a simple object.
The fingerprint of a state is built by concatenating the sorted
names of the state's properties (property
id is not included in
the computation of the fingerprint).
;const state =id: '1234'begin: 12end: 23;to;
The states are managed by class
FieldStates, which maintains a read-only
array of simple state objects. An instance of
FieldStates is immutable.
To create a
FieldStates instance, use one of the static methods:
FieldStates.create ()→ creates an empty states collection.
FieldStates.from (s1, s2, ...)→ create a states collection based on the provided states
To manipulate a
add (state)→ adds or updates the state based; matching with any existing states is based on the fingerprint.
remove (state)→ removes the state.
find (state)→ returns the immutable state (if it is found) or
get ()→ returns an immutable array of immutable states, as they are stored in the
find() accept either a simple object (the
values of the fields are not used in the comparison) or a fingerprint
to specify the state.
remove() return a new instance of
the state changes; otherwise, they just return the same instance.
Note: states are considered to be equal if they respond
trueto shallow equality. Since states should be simple objects where all properties are just value types, a shallow comparison is enough.