MingaEditor.FeatureState (Minga v0.1.0)

Copy Markdown View Source

Source-owned per-workspace UI feature state.

Feature state is for presentation features that need tab-scoped state without adding permanent fields to MingaEditor.Session.State. Values are opaque to the registry. The owning feature decides the value shape and updates it through the helpers here and on MingaEditor.Session.State.

Summary

Types

Feature state registry keyed first by source and then by feature id.

Feature identifier owned by a source.

Source that owns feature state.

t()

Opaque feature-owned value.

Functions

Drops one source-owned feature value.

Drops every extension-owned feature value while preserving built-in and config state.

Drops every feature value owned by source.

Returns true when no feature state is stored.

Registers the source-cleanup callback used by extension unload/reload.

Fetches a source-owned feature value.

Returns the value for a source-owned feature, or nil when missing.

Returns the value for a source-owned feature, or a caller-provided default when missing.

Returns true when the source owns the feature id.

Creates an empty feature-state registry.

Stores a source-owned feature value.

Cleanup callback bridge against an explicit editor server. Useful for tests.

Updates a source-owned feature value. Missing values are initialized with default.

Returns true for supported feature ids.

Returns true for supported contribution source identifiers.

Types

entries()

@type entries() :: %{optional(source()) => %{optional(feature_id()) => value()}}

Feature state registry keyed first by source and then by feature id.

feature_id()

@type feature_id() :: atom()

Feature identifier owned by a source.

source()

Source that owns feature state.

t()

@type t() :: %MingaEditor.FeatureState{entries: entries()}

value()

@type value() :: term()

Opaque feature-owned value.

Functions

drop(state, source, feature_id)

@spec drop(t(), source(), feature_id()) :: t()

Drops one source-owned feature value.

drop_extension_sources(state)

@spec drop_extension_sources(t()) :: t()

Drops every extension-owned feature value while preserving built-in and config state.

drop_source(state, source)

@spec drop_source(t(), source()) :: t()

Drops every feature value owned by source.

empty?(feature_state)

@spec empty?(t()) :: boolean()

Returns true when no feature state is stored.

ensure_cleanup_registered()

@spec ensure_cleanup_registered() :: :ok

Registers the source-cleanup callback used by extension unload/reload.

fetch(feature_state, source, feature_id)

@spec fetch(t(), source(), feature_id()) :: {:ok, value()} | :error

Fetches a source-owned feature value.

get(state, source, feature_id)

@spec get(t(), source(), feature_id()) :: value() | nil

Returns the value for a source-owned feature, or nil when missing.

get(state, source, feature_id, default)

@spec get(t(), source(), feature_id(), default) :: value() | default when default: var

Returns the value for a source-owned feature, or a caller-provided default when missing.

member?(state, source, feature_id)

@spec member?(t(), source(), feature_id()) :: boolean()

Returns true when the source owns the feature id.

new()

@spec new() :: t()

Creates an empty feature-state registry.

put(state, source, feature_id, value)

@spec put(t(), source(), feature_id(), value()) :: t()

Stores a source-owned feature value.

unregister_source(source)

@spec unregister_source(source()) :: :ok | {:error, term()}

Cleanup callback bridge used by Minga.Extension.ContributionCleanup.

unregister_source(source, editor_server)

@spec unregister_source(source(), GenServer.server() | nil) :: :ok | {:error, term()}

Cleanup callback bridge against an explicit editor server. Useful for tests.

update(state, source, feature_id, default, fun)

@spec update(t(), source(), feature_id(), value(), (value() -> value())) :: t()

Updates a source-owned feature value. Missing values are initialized with default.

valid_feature_id?(feature_id)

@spec valid_feature_id?(term()) :: boolean()

Returns true for supported feature ids.

valid_source?(arg1)

@spec valid_source?(term()) :: boolean()

Returns true for supported contribution source identifiers.