Skip to main content

impulse_signals 0.6.0 copy "impulse_signals: ^0.6.0" to clipboard
impulse_signals: ^0.6.0 copied to clipboard

An integration of signals into the impulse_flutter package.

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 #

  • impulse for core concepts and advanced usage.
  • impulse_flutter for a full documentation of impulse and how to use it in Flutter.
  • API reference for a detailed description of all API points.

License #

This project is licensed under the MIT License.

1
likes
0
points
266
downloads

Publisher

verified publishervanzwolsoftware.nl

Weekly Downloads

An integration of signals into the impulse_flutter package.

Repository (GitHub)
View/report issues

Topics

#state #signals

License

unknown (license)

Dependencies

flutter, impulse_flutter, signals_flutter

More

Packages that depend on impulse_signals