Impulse Signals

Tests codecov License: MIT

Impulse extension for signals by Rody Davis. This package provides a Controller class that simplifies managing the lifecycle of multiple signals and effects, similar to SignalsMixin. It also exports impulse_flutter and signals_flutter so everything is neatly provided in a single library.

The package is currently being implemented in some production-level code to validate its real-world use. It will hit 1.0 after this is complete.

Features

  • Controller Base Class: Group related signals and effects together.
  • Automatic Disposal: Signals and effects created through the controller are automatically disposed of when the controller is dropped from the Impulse store.
  • Support for All Signal Types: Includes helpers for standard signals, computed signals, future signals, stream signals, and more.

Getting Started

Add impulse_signals to your pubspec.yaml:

dependencies:
  impulse_signals: latest

Usage Example

final themeControllerRef = Ref((store) => ThemeController());

class ThemeController extends Controller {
  // createSignal registers the signal for automatic disposal
  late final themeMode = createSignal(ThemeMode.system);
  late final seedColor = createSignal<Color>(Colors.deepPurple);

  // createComputed registers the computed signal for automatic disposal
  late final colorScheme = createComputed(() =>
    ColorScheme.fromSeed(seedColor: seedColor.value, brightness: Brightness.light)
  );

  void setThemeMode(ThemeMode mode) => themeMode.value = mode;
  void setSeedColor(Color color) => seedColor.value = color;
}

The package also changes impulse's method to work with errors to use signal's AsyncError class for the Result<T> type.

final (value, err) = attempt(() => myApiCall(...));

// err is `AsyncError` from signals
// contains the error and the stacktrace
if(err != null){
  print('Error oh no! ${err.error}')
  print(err.stackTrace);
}

// value is value on succes
print('Retrieved value $value');

See also

License

This project is licensed under the MIT License.

Libraries

impulse_signals
Signals integration for the Impulse state management library.