SignalModel#
Kind:
class |
Package: package:preact_signals
Class: SignalModel#
A premium wrapper for cohesive state packages constructed with createModel.
It holds the instanced model value and all the Effects that were captured during its construction. Disposing the SignalModel automatically disposes of all nested/captured effects, completely avoiding memory leaks.
Premium Pattern: Dart 3+ Extension Type Wrappers#
To avoid unchecked subscript access like model['count'].value, wrap your model in an extension type:
extension type TypeSafeCounter(SignalModel<Map<String, dynamic>> _model) {
int get count => (_model['count'] as Signal<int>).value;
set count(int val) => (_model['count'] as Signal<int>).value = val;
void increment() => (_model['increment'] as Function)();
void dispose() => _model.dispose();
}
Members of SignalModel#
| Member | Type | Signature | Description |
|---|---|---|---|
| value | field |
dart T value |
The instanced model value. |
| options | field |
dart SignalModelOptions options |
Options used to configure this model. |
| SignalModel | constructor |
dart SignalModel(this.value, this._effects, {this.options = const SignalModelOptions()})
|
Creates a new model instance. |
| [] | method |
dart dynamic [](Object? key) |
Access properties dynamically if the underlying value is a Map. |
| []= | method |
dart void []=(dynamic key, dynamic val) |
Set properties dynamically if the underlying value is a Map. |
| call | method |
dart T call() |
Returns the value of this model. Alias for [.value] |
| dispose | method |
dart void dispose() |
Disposes of all captured effects. |
References#
The SignalModel type is referenced and used in the following pages: