primitives library
Contains fundamental primitives and change notification types used throughout the extensions package.
This library provides isolated types that are shared across multiple components, inspired by Microsoft.Extensions.Primitives.
Change Tokens
Track and react to changes in data sources:
// Create a change token source
final cts = CancellationTokenSource();
final changeToken = CancellationChangeToken(cts.token);
// Register a callback
changeToken.registerChangeCallback(() {
print('Data changed!');
});
// Signal change
cts.cancel();
Change Token Patterns
Use utility methods for common patterns:
// React to changes with state
ChangeToken.onChangeTyped<MyData>(
() => dataSource.getChangeToken(),
(data) => print('New data: $data'),
);
// Composite change tokens
final token = CompositeChangeToken([token1, token2, token3]);
// Fires when any constituent token changes
Validation
Use validation results for options validation:
ValidationResult.success();
ValidationResult.fail('Invalid value');
Classes
- CancellationChangeToken
- A IChangeToken implementation using CancellationToken.
- ChangeToken
- CompositeChangeToken
- An ChangeToken which represents one or more ChangeToken instances.
- IChangeToken
- Propagates notifications that a change has occurred.
- ValidationResult
Typedefs
- ChangeCallback = void Function(Object? state)
- Callback signature for change notifications.
- ChangeTokenConsumer = void Function()
- Action called when the token changes.
- ChangeTokenProducer = IChangeToken? Function()
- Produces the change token.
-
ChangeTokenTypedConsumer<
TState> = void Function(TState? state) - Action called when the token changes with state.
- VoidCallback = void Function()
Exceptions / Errors
- AggregateException
- Represents one or more errors that occur during application execution.