base library
Base cloning implementation and interface for custom cloning strategies.
This library provides the foundational types for building cloning implementations:
- BaseCloner: Default deep-cloning implementation for collections and ICloneable types
- ICloning + IClonerBuilding: Interfaces for creating custom cloning strategies
Difference from core.dart:
core.dartexports the high-level Cloner API for everyday usebase.dartexports lower-level primitives for advanced customization
When to use base.dart:
- Implementing a custom ICloning strategy (e.g., logging, metrics, special type handling)
- Directly instantiating BaseCloner with specific options using builder pattern
- Building frameworks or libraries that extend cloning behavior
Classes
- AdaptiveCloner
- Dispatches cloning operations to appropriate delegates based on configuration.
- AdaptiveClonerBuilder
- Builder for AdaptiveCloner, allowing configuration of delegates and mode.
- BaseCloneLogger
- Base logger for clone operations, storing log history and controlling log output.
- BaseCloner
-
Performs element/value-wise cloning for built-in collections and delegates
to
ICloneableimplementations for custom types. - BaseClonerBuilder
- Builder for BaseCloner
- CountedCloner
- Extends BaseCloner with enforced recursion and size limits. The lightest way to prevent StackOverflow for circular references.
- CountedClonerBuilder
- Builder for CountedCloner
- HashedCloner
- Cloner with circular reference detection.
- HashedClonerBuilder
- Builder for HashedCloner
- IBuildable
- Interface for extracting a builder from an instance, enabling constructorless builder access.
-
ICloneable<
T extends Object> -
Contracts used by
Clonerand collection helpers. - IClonerBuilding
- Interface for types that can construct an ICloning instance (builder pattern).
- ICloning
- Agent interface for types that perform cloning operations (i.e., cloners).
-
ICopyable<
T extends Object> - Use for a shallow, element-wise copy.
- IListCloning
- Interface for cloning list structures.
-
ILoggable<
T> -
Provides logging functionality for messages of type
T. -
ILogging<
T> - Combines logging, log retrieval, and print control.
- IMapCloning
- Interface for cloning map structures.
- IMapTypedCloning
- Interface for cloning map structures.
-
IPrintLogging<
T> - Controls printing of log messages.
- IRestorable
- Provides a contract for objects that can be restored to their initial state.
-
ISerializable<
O, D> -
Contract for serializing an object
Oto dataD. - ISetCloning
- Interface for cloning set structures.
-
IShowLogging<
T> - Exposes access to the log messages.
- IValueCloning
- Interface for cloning single values.
- PureCloner
- Performs deep cloning for common Dart collections and objects. Does not preserve type arguments or underlying collection implementations.
- PureClonerBuilder
-
Placeholder builder to enable PureCloner usage inside
Cloner.
Mixins
- MBaseClonerLogging
- Mixin that adds logging capabilities to BaseCloner using BaseCloneLogger. Provides access to log history via showLogs and allows resetting logs with reset.
- MClonerLogging
- Mixin that provides logging for cloning operations using BaseCloneLogger.
Functions
-
deserializeBaseFlag(
String data, {required String prefix}) → bool - Deserializes the base flag and returns true if typed clone, false if dynamic.
-
serializeBaseFlag(
{required bool doTypedClone, String? prefix}) → String - Serializes the base flag for clone type, optionally prefixed.
Typedefs
-
ISerializableAsync<
O, D> = ISerializable< O, Future< D> > -
Asynchronous variant of ISerializable where serialization returns a
Future.