convert<T, U> method
ConvertComputed<T, U>
convert<T, U>(
- WritableNode<
U> source, - T decode(
- U value
- U encode(
- T value
- JoltDebugFn? onDebug,
Creates a type-converting computed hook.
Automatically converts between different types while maintaining reactivity.
Parameters:
source: The source signal to convert fromdecode: Function that converts from source type to target typeencode: Function that converts from target type back to source typeonDebug: Optional debug callback for reactive system debugging
Returns: A ConvertComputed with type conversion capabilities
Example:
setup(context, props) {
final count = useSignal(42);
final countText = useComputed.convert(
count,
(int value) => value.toString(),
(String value) => int.parse(value),
);
return () => TextField(
controller: TextEditingController(text: countText.value),
onChanged: (text) => countText.value = text,
);
}
Implementation
ConvertComputed<T, U> convert<T, U>(WritableNode<U> source,
T Function(U value) decode, U Function(T value) encode,
{JoltDebugFn? onDebug}) {
return useAutoDispose(() => ConvertComputed<T, U>(source,
decode: decode, encode: encode, onDebug: onDebug));
}