Skip to main content

an_reactive_state 1.2.1 copy "an_reactive_state: ^1.2.1" to clipboard
an_reactive_state: ^1.2.1 copied to clipboard

A high-performance synchronous reactive graph engine for Dart. Features lazy evaluation, async isolation via Zones, and absolute memory safety with Cancellable.

example/example.dart

import 'package:cancellable/cancellable.dart';
import 'package:an_reactive_state/an_reactive_state.dart';

void main() {
  final scope = Cancellable();

  // 1. Declare raw state atoms
  final price = RState<double>(initialValue: 99.0, cancellable: scope);
  final count = RState<int>(initialValue: 1, cancellable: scope);

  // 2. Declare a high-order derived calculation state
  final totalPrice = ComputedState<double>(
    cancellable: scope,
    computer: () =>
        price.value * count.value, // Automatically tracks price and count
  );

  // 3. Register a side effect: whatever reactive states it reads inside the block,
  // it will automatically re-run whenever those states change.
  effect(() {
    print('【UI Effect Card】Current total checkout amount: ${totalPrice.value}');
  }, cancellable: scope);

  print('--- Modifying Quantity ---');
  count.value = 3; // Executed synchronously inside the current call stack

  scope
      .cancel(); // Everything self-destructs; subsequent writes are safely blocked.
}
0
likes
160
points
397
downloads

Documentation

API reference

Publisher

verified publisheraymtools.com

Weekly Downloads

A high-performance synchronous reactive graph engine for Dart. Features lazy evaluation, async isolation via Zones, and absolute memory safety with Cancellable.

Repository (GitHub)
View/report issues

License

Apache-2.0 (license)

Dependencies

cancellable

More

Packages that depend on an_reactive_state