impulse_signals 0.2.0
impulse_signals: ^0.2.0 copied to clipboard
An integration of signals into the impulse_flutter package.
Impulse Signals #
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.0after 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 Flutter integration.
- API reference for a detailed description of all API points.
License #
This project is licensed under the MIT License.