Signals for Dart

repository·main·Indexed 21 days ago

https://github.com/rodydavis/signals.dart

A fine-grained reactivity library for the Dart ecosystem inspired by Preact Signals. It provides automatic dependency tracking and lazy evaluation for state management across CLI, Server, and Flutter applications. The ecosystem includes the core signals package, signals_flutter for surgical widget rebuilding, signals_hooks for integration with flutter_hooks, and signals_lint for code quality.

Tokens
208.3K
Snippets
589
Records
817
Agent score
72%

What's inside signals.dart

  1. Overview of signals_flutter package contents

    main

    The signals_flutter package provides a comprehensive suite of tools for reactive programming in Flutter using signals. The package is organized into several functional categories:

    • Core Primitives: Basic building blocks like Signal, Computed, Effect, Action, Batch, LinkedSignal, ReadonlySignal, and Untracked.
    • Async Primitives: Tools for handling asynchronous data, including AsyncState, AsyncSignal, AsyncComputed, Connect, FutureSignal, and Stream.
    • Reactive Collections: Specialized signals for collections such as ListSignal, MapSignal, SetSignal, IterableSignal, and ChangeStackSignal.
    • Reactive Mixins: Mixins to add reactivity to existing classes, such as ListSignalMixin, MapSignalMixin, ValueNotifierSignalMixin, and StreamSignalMixin.
    • Utilities: Helper tools like SignalContainer, Model, SignalsObserver, PersistedSignal, and SignalEquality.
    • Widget & Context Extensions: Extensions to bridge signals with Flutter's widget tree, including ValueListenableToSignal, ValueNotifierToSignal, and various StatefulWidget/StatelessWidget converters.
    • Reactive Signals: Flutter-specific signal implementations like FlutterSignal, FlutterComputed, and TickerSignal.
    • Flutter Widgets: UI components for consuming signals, such as SignalBuilder, Watch, WatchBuilder, SignalProvider, and SignalAnimatedBuilder.
    • Low-Level Render Objects: Custom render objects for advanced usage, including RenderSignalBox and RenderSignalCustomPaint.
    • Lifecycle & Effects: Lifecycle management tools like SignalEffect.
  2. Overview of signals_core

    main
    signals_core is a high-performance, 100% pure Dart reactivity library based on the Preact Signals model. It is designed to work across all Dart environments, including CLI, server-side, web, and Flutter. It provides fine-grained state management with automatic dependency tracking, lazy evaluation, and smart cache invalidation.
  3. Overview of signals_flutter integration patterns

    main

    The signals_flutter package provides structured patterns for integrating pure Dart reactive state into Flutter applications. It is designed to build high-performance, memory-safe, and GPU-optimized user interfaces by leveraging reactive primitives.

    Key areas of integration include:

    • Core Primitives: Writable signals, readonly encapsulation, computed derived state, effects, and batching mutations.
    • Asynchronous State: Managing loading/success/error states, futures, streams, and composable async operations.
    • Reactive Collections: Element-level reactivity for Lists, Sets, Maps, Iterables, and Queues.
    • UI Components: Using specialized widgets like SignalBuilder for isolated rebuilds, SignalWidget for implicit state, and SignalCustomPaint for high-frequency (120fps) GPU-direct painting.
    • Contextual Reactivity: Using extensions like watch for automatic lifecycle-managed subscriptions.
  4. Overview of Signals for Flutter

    main

    Signals for Flutter provides a fine-grained reactivity system inspired by Preact Signals. It is designed to optimize performance in Flutter applications through automatic dependency tracking and surgical widget rebuilding.

    Key features include:

    • Fine-grained reactivity: Automatically tracks dependencies and frees them when no longer needed.
    • Lazy evaluation: Signals only compute values when they are actually read.
    • Surgical Rendering: Only the specific parts of the Widget tree that depend on a signal are marked as dirty and rebuilt, minimizing unnecessary work.
    • 100% Dart Native: Works across all Dart environments, including Flutter (Web, Mobile, Desktop), CLI, Shelf Server, and Dart JS.
  5. Overview of signals_core features

    main

    The signals_core package provides a platform-agnostic, zero-dependency reactive framework for Dart. Key capabilities include:

    • Core Primitives: Signals, Computeds, Effects, and LinkedSignals for basic reactivity.
    • Async Bindings: futureSignal and streamSignal to bind asynchronous data to reactive states.
    • Reactive Collections: Specialized signals for collections like listSignal, setSignal, mapSignal, and iterableSignal.
    • Undo/Redo: changeStack for tracking value histories.
    • Mixins & Utilities: Various mixins (e.g., SinkSignalMixin) and utilities (e.g., SignalContainer, Model) to extend reactive functionality.
  6. Overview of signals_hooks features

    main

    The signals_hooks package provides type-safe bindings for flutter_hooks to enable reactive programming within functional widgets. Key capabilities include:

    • Hook-based Signalling: Use useSignal() to declare state within functional widgets.
    • Automatic Disposal: Signals managed via hooks are automatically cleaned up, eliminating the need for manual dispose() overrides.
    • Computed & Async States: Use useComputed for cacheable computations and useAsyncComputed for managing asynchronous states within the hook lifecycle.
  7. Overview of the signals package

    main

    The signals package is the primary entry point for the Signals framework. It provides a unified developer experience by exporting:

    • signals_core: The core reactive engine containing signals, computations, batch updates, and reactive collections.
    • signals_flutter: Full Flutter extensions for seamless state management in Flutter applications.

    It is designed to support any Dart environment, including Flutter (Mobile, Web, Desktop), CLI, Shelf Server, and HTML/JS.

  8. Overview of Signals.dart features

    main

    Signals.dart is a fine-grained reactivity system for Dart, inspired by Preact Signals. It is designed to be 100% Dart native, supporting environments ranging from Flutter (Web, Mobile, Desktop) and Dart JS (HTML) to Shelf Server, CLI, and VM.

    Key features include:

    • Fine-grained reactivity: Automatically tracks and manages dependencies.
    • Lazy evaluation: Signals only compute values when they are actually read.
    • Surgical Rendering: In Flutter, it allows for rebuilding only the specific parts of the widget tree that need updates, minimizing overhead.
  9. Overview of Signals for Dart

    main

    Signals for Dart is a fine-grained reactivity system inspired by Preact Signals. It is designed to automatically track dependencies and manage their lifecycles, ensuring that resources are freed when no longer needed.

    Key characteristics include:

    • Fine-grained reactivity: Automatic dependency tracking.
    • Lazy evaluation: Values are only computed when they are actually read.
    • Surgical Rendering: When used with supported frameworks (like Flutter), it allows for rebuilding only the specific parts of the widget tree that changed.
    • Platform Agnostic: 100% Dart native, supporting Dart JS (HTML), Shelf Server, CLI, VM, and Flutter (Web, Mobile, and Desktop).
  10. Overview of signals_core primitives

    main

    The signals_core package provides several categories of reactive primitives:

    Core Primitives

    Foundational building blocks for state management:

    • Action, Batch, Signal, Computed, Effect, LinkedSignal, ReadonlySignal, Untracked.

    Async Primitives

    For binding asynchronous operations to reactive state:

    • AsyncState, AsyncSignal, Computed (async), Connect, FutureSignal, Stream.

    Reactive Collections

    Specialized signals for managing collections:

    • ChangeStackSignal, IterableSignal, ListSignal, MapSignal, SetSignal.

    Reactive Mixins

    Mixins to add reactive capabilities to existing types:

    • ChangeStackSignalMixin, EventSinkSignalMixin, IterableSignalMixin, ListSignalMixin, MapSignalMixin, QueueSignalMixin, SetSignalMixin, SinkSignalMixin, StreamSignalMixin, TrackedSignalMixin.

    Utilities

    Helper tools for advanced usage:

    • SignalContainer, Model, SignalsObserver, PersistedSignal, SignalEquality.
  11. Understand the Signals.dart package ecosystem

    main

    The signals.dart ecosystem is a modular reactivity framework for Dart and Flutter. Depending on your project type, you should choose the appropriate package:

    • signals: The recommended umbrella package for most users.
    • signals_core: The primary Dart API featuring advanced types and extensions.
    • signals_flutter: Provides native Flutter widgets and lifecycle management.
    • signals_hooks: Specifically for users integrating with flutter_hooks.
    • signals_lint: Provides custom linter rules to ensure best practices.
    • signals_devtools_extension: An inspector for use within Flutter DevTools.
    • preact_signals: Low-level internal engine (not intended for direct use).
  12. Features of the Signals DevTools extension

    main

    The signals_devtools_extension provides several advanced debugging capabilities:

    • Real-Time Updates Timeline: A chronological stream of signal mutations, computation re-evaluations, and side effect executions with value diffs and microsecond timestamps.
    • Interactive Physics Node Graph: A visual representation of your application's reactive structure, showing the flow from Signals to Computeds to Effects or widgets.
    • Reaction Pause & Replay: The ability to freeze the reactive event stream, snapshot states, and play/resume events to step through microtask mutations.
    • Deep Node Metadata Drawer: An inspector for any reactive node that displays its ID, debug label, stringified value, and lists of upstream sources and downstream targets.
    • Diagnostic Logging & Coalescing: Options to enable VM console logging or group sequential microtask updates to inspect coalesced batches.