levit_dart_core 0.0.5 copy "levit_dart_core: ^0.0.5" to clipboard
levit_dart_core: ^0.0.5 copied to clipboard

The core framework for pure Dart applications. Aggregates dependency injection and reactivity.

levit_dart_core #

Pub Version Platforms License: MIT codecov

The foundational composition layer for the Levit ecosystem. Explicit. Reactive. Deterministic.

levit_dart_core orchestrates the relationship between [levit_reactive] primitives and [levit_scope] dependency management into a structured framework for building pure Dart business logic.


Purpose & Scope #

levit_dart_core provides a predictable environment for managing application logic without UI dependencies. It is responsible for:

  • Lifecycle Orchestration: Defining how components are initialized, attached to scopes, and disposed.
  • Automated Resource Management: Ensuring all streams, timers, and reactive objects are cleaned up deterministically.
  • Composition Conventions: Providing both class-based ([LevitController]) and functional ([LevitState]) abstractions for logic.

It deliberately avoids UI or platform-specific logic, making it suitable for CLI tools, servers, and background services. For Flutter integration, use levit_flutter_core.


Conceptual Overview #

Application Elements #

  • [LevitController]: A managed component that encapsulates state and behavior. It participates in an explicit lifecycle and uses autoDispose for resource management.
  • [LevitState]: A functional provider that acts as a factory for state instances, offering a modern alternative to class-based controllers.
  • [Levit]: The central registry and entry point for managing scopes and resolving dependencies.

Key Mechanisms #

  • Ambient Scoping: Uses Zone-based propagation via levit_scope to resolve dependencies implicitly without manual passing.
  • Auto-Linking: Automatically tracks reactive state created within a controller or state builder to ensure zero-leak disposal.

Getting Started #

1. Define a Controller #

class CounterController extends LevitController {
  // Logic is automatically registered for cleanup
  late final count = autoDispose(0.lx);

  void increment() => count.value++;
}

2. Register and Resolve #

void main() {
  // Register the controller in the current scope
  Levit.put(() => CounterController());
  
  // Resolve and use
  final controller = Levit.find<CounterController>();
  controller.increment();
}

Design Principles #

Explicit over Implicit #

While [Levit] provides ambient scoping for ergonomics, every state transition and dependency link is trackable and deterministic.

Managed Lifecycle #

Resources are never left to the garbage collector alone. The onClose hook and autoDispose mechanism ensure that all side effects are terminated as soon as a component is removed.

Functional Composition #

The framework encourages composing logic via [LevitState] to reduce boilerplate and improve encapsulation, while providing [LevitController] for more complex or hierarchical logic.

1
likes
150
points
134
downloads

Publisher

unverified uploader

Weekly Downloads

The core framework for pure Dart applications. Aggregates dependency injection and reactivity.

Repository (GitHub)
View/report issues
Contributing

Topics

#state-management #dependency-injection #framework

Documentation

API reference

License

MIT (license)

Dependencies

levit_reactive, levit_scope, meta

More

Packages that depend on levit_dart_core