LogoSignals.dart
Copy Markdown
rodydavis/signals.dart 999999

Type: PersistedSignalMixin

API reference and details for PersistedSignalMixin from signals.dart.

PersistedSignalMixin#

Kind: mixin  |  Package: package:signals_core

Mixin: PersistedSignalMixin#

A mixin that adds local persistence capabilities to a standard Signal.

By mixing in PersistedSignalMixin on a Signal subclass, the signal will automatically retrieve its stored state on boot and save its state whenever .value is mutated.

Classes mixing in PersistedSignalMixin must implement:

  • key: A unique identifier string for the key-value database.
  • store: An implementation of SignalsKeyValueStore.

Serialization Customization#

By default, the mixin uses standard JSON parsing (jsonDecode / jsonEncode). If your data type T is not natively supported by JSON, override:

  • decode to convert the raw string value back into type T.
  • encode to serialize type T into a string.

Members of PersistedSignalMixin#

Member Type Signature Description
key method dart String key The key to use for storing the value.
store method dart SignalsKeyValueStore store The store to use for storing the value.
loaded field dart bool loaded Whether the signal has been loaded from the store.
init method dart Future init() Initializes the signal by loading the value from the store.
value method dart T value
value method dart value(T value)
load method dart Future load() Loads the value from the store.
save method dart Future save(T value) Saves the value to the store.
decode method dart T decode(String value) Decodes the value from a string.
encode method dart String encode(T value) Encodes the value to a string.

References#

The PersistedSignalMixin type is referenced and used in the following pages: