'cell:core' is a reactive programming framework centered around the Cell class and its extensions, particularly the Collective family of classes that implement reactive collections CollectiveSet, CollectiveList, CollectiveQueue and CollectiveValue. This framework provides a comprehensive reactive programming solution for Dart, with particular strength in managing complex state and data flow in applications.
Key features include:
-
Reactive Programming Model: Automatic propagation of changes through a network of cells
-
Validation System: Configurable rules for what operations are allowed
-
Flexible Signal Processing: Customizable signal transformation and propagation
-
Collection Support: Reactive versions of common collection types (Set, List, Queue, Value)
-
Modifiable/Unmodifiable Views: Both mutable and immutable variants of all containers
-
Asynchronous Support: Async interfaces for modifiable operations
Core components that work together:
- Cell: The fundamental reactive unit
- Receptor: Handles signal processing
- Synapses: Manages inter-cell communication
- Properties: Contains cell configuration
- TestRule/TestObject: Provides validation
- Signal: Carries data between cells
- Deputy: Enables behavior modification
Cells can be:
- Bound to other cells to form relationships
- Linked to create observable patterns
- Modified through receptors and test objects
Example:
// Create a basic cell
final cell = Cell();
final boundCell = Cell(bind: cell);
// Create a listening cell
final listener = Cell.listen<String>(
bind: baseCell,
listen: (signal, _) => print('Received: ${signal.body}'),
);
// Create a transforming cell
final transformer = Cell.signaling<String, int>(
bind: baseCell,
map: (signal, _) => signal.body?.length,
);
Example: with Collective bounded
// Create source cell
final source = CollectiveValue<int>(5);
// Create transformed cell
final squared = Cell.signaling<int,int>(
bind: source,
transform: (signal, _) => Signal(signal.body * signal.body)
);
// Create logger
final logger = Cell.listen<int>(
bind: squared,
listen: (signal, _) => print('Value squared: ${signal.body}')
);
// Update source - automatically propagates
source.value = 10; // Logs "Value squared: 100"
- Implementers
Constructors
-
Cell.new({Cell? bind, Receptor<
Cell, Signal, Signal> receptor, TestObject<Cell> test, Synapses<Signal, Cell> synapses}) -
Creates a new Cell with optional binding and configuration
factory
-
Cell.deputy({required Cell bind, TestObject<
Cell> ? test, MapObject? mapObject}) -
A factory constructor that creates an Deputy cell from an existing Cell instance with reduced permissions.
factory
- Cell.fromProperties(Properties properties)
-
Constructs a Cell from predefined properties.
factory
Properties
-
async
→ CellAsync<
Cell> -
Creates an async variant for modifiable operations
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
-
modifiable
→ Iterable<
Function> -
Returns an iterable containing modifiable functions.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
test
→ TestObject<
Cell> -
Gets the test object associated with the cell.
no setter
- unmodifiable → Cell
-
Creates an unmodifiable view of this cell.
no setter
Methods
-
apply(
Function function, List? positionalArguments, [Map< Symbol, dynamic> ? namedArguments]) → dynamic - Applies a function with controlled validation.
-
deputy(
{covariant TestObject< Cell> ? test, covariant MapObject? mapObject}) → Cell - Creates an Deputy cell from an existing Cell instance with reduced permissions.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
listen<
S extends Signal> ({required Cell bind, required void listen(S signal, dynamic user), dynamic user, Synapses< Signal, Cell> synapses = Synapses.disabled}) → Cell - Creates a listening cell that executes a callback when signals are received
-
open<
C extends Cell, L extends Cell, I extends Signal, O extends Signal> ({Cell? bind, Receptor< C, I, O> ? receptor, TestObject<Cell> test = TestObject.passed, Synapses<O, L> ? synapses}) → OpenCell<Cell, Cell, Signal, Signal> - Creates an open Cell that supports linking and receptor transformations.
-
signaling<
I extends Signal, O extends Signal> ({required Cell bind, required O? transform(I signal, dynamic user), dynamic user, Synapses< Signal, Cell> synapses = Synapses.enabled}) → Cell - Creates a signaling Cell that transforms incoming and outgoing signals, or stop outgoing signals.