LogoSignals.dart
Copy Markdown
rodydavis/signals.dart 999999

Type: readonly

API reference and details for readonly from signals.dart.

readonly#

Kind: function  |  Package: package:preact_signals

Function: readonly#

ReadonlySignal<T> readonly(T value, [ReadonlySignalOptions<T>? options])

Creates a new read-only signal initialized with value.

This function returns a ReadonlySignal containing value. Under the hood, a mutable Signal is created, but it is returned under the ReadonlySignal interface to prevent modification by clients.

This is particularly useful when you need to expose a constant reactive value, or bridge some external, immutable value source into the signals reactivity system.

Parameters:

  • value: The initial value held by the read-only signal.
  • options: Optional configuration options (e.g., custom debug name or lifecycle callbacks like watched/unwatched).

Returns:

Example Usage#

import 'package:preact_signals/preact_signals.dart';

final configUrl = readonly('https://api.example.com');

void main() {
  effect(() {
    print("Connecting to: ${configUrl.value}");
  });
}
If you are trying to derive a value from other signals, do not use [readonly]. Use [computed] instead to ensure the derived signal automatically re-evaluates when its source signals change.

Function: readonly#

ReadonlySignal<T> readonly(T value, {ReadonlySignalOptions<T>? options, @Deprecated('Use options: ReadonlySignalOptions(autoDispose: ...) instead') bool? autoDispose, @Deprecated('Use options: ReadonlySignalOptions(name: ...) instead') String? debugLabel})

Creates a new read-only signal initialized with value.

This function returns a ReadonlySignal containing value. Under the hood, a mutable Signal is created, but it is returned under the ReadonlySignal interface to prevent modification by clients.

This is particularly useful when you need to expose a constant reactive value, or bridge some external, immutable value source into the signals reactivity system.

Parameters:

  • value: The initial value held by the read-only signal.
  • options: Optional configuration options (e.g., custom debug name or lifecycle callbacks).

Returns:

Example Usage#

import 'package:signals_core/signals_core.dart';

final configUrl = readonly('https://api.example.com');

void main() {
  effect(() {
    print("Connecting to: ${configUrl.value}");
  });
}
If you are trying to derive a value from other signals, do not use readonly. Use computed instead to ensure the derived signal automatically re-evaluates when its source signals change.

Function: readonly#

FlutterReadonlySignal<T> readonly(T value, {core.SignalOptions<T>? options, @Deprecated('Use options: SignalOptions(name: ...) instead') String? debugLabel, @Deprecated('Use options: SignalOptions(autoDispose: ...) instead') bool? autoDispose, bool runCallbackOnListen = false})

Create a new plain readonly signal

References#

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