convert<T, U> method

ConvertComputed<T, U> convert<T, U>(
  1. WritableNode<U> source,
  2. T decode(
    1. U value
    ),
  3. U encode(
    1. T value
    ), {
  4. JoltDebugFn? onDebug,
})

Creates a type-converting computed hook.

Automatically converts between different types while maintaining reactivity.

Parameters:

  • source: The source signal to convert from
  • decode: Function that converts from source type to target type
  • encode: Function that converts from target type back to source type
  • onDebug: 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));
}