PersistSignalImpl<T> constructor

PersistSignalImpl<T>({
  1. required FutureOr<T> read(),
  2. required FutureOr<void> write(
    1. T value
    ),
  3. T initialValue()?,
  4. bool lazy = false,
  5. Duration writeDelay = Duration.zero,
  6. JoltDebugFn? onDebug,
})

Creates a persistent signal with the given configuration.

Parameters:

  • initialValue: Optional function that returns the initial value if storage is empty
  • read: Function to read the value from storage
  • write: Function to write the value to storage
  • lazy: Whether to load the value lazily (on first access)
  • writeDelay: Delay before writing to storage (for debouncing)
  • onDebug: Optional debug callback

If lazy is false, the value will be loaded from storage immediately. If lazy is true, the value will be loaded on first access via value or get.

Implementation

PersistSignalImpl(
    {required this.read,
    required this.write,
    T Function()? initialValue,
    bool lazy = false,
    this.writeDelay = Duration.zero,
    super.onDebug})
    : super(initialValue != null ? initialValue() : null) {
  if (!lazy) {
    unawaited(_load());
  }
}