ScopedRef<T> class
A reference to a scoped value of type T
It can be isLocal (if true) or global. If it's local, one instance will be created for every scope and it's descendants. If it's global (isLocal == false) one instance will be created for every scope and all its parents. When the reference is created, it will be set to the scoped map and to every parent's scoped map.
final valueRef = ScopedRef<String>.global(
(ScopedMap scope) => 'Value'
);
/// [ctx] can be anything that implements [ScopedHolder]
/// For example, any of [ReqCtx], [ResolveCtx] or [ResolveObjectCtx]
void makeAction(ScopedHolder ctx) {
final String value = valueRef.get(ctx);
}
// TODO: 1A do not allow to access scoped from globals
Constructors
-
ScopedRef(T create(ScopedMap scope), {required bool isLocal, String? name, FutureOr<
void> dispose(T value)?}) -
A reference to a scoped value of type
T
-
ScopedRef.global(T create(ScopedMap scope), {String? name, FutureOr<
void> dispose(T value)?}) -
ScopedRef.local(T create(ScopedMap scope), {String? name, FutureOr<
void> dispose(T value)?})
Properties
- create → T Function(ScopedMap scope)
-
The function used to create the value for this reference
final
-
dispose
→ (FutureOr<
void> Function(T value)?) -
The function used to dispose the value created for this reference
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- isGlobal → bool
-
Whether the value is local or global
no setter
- isLocal → bool
-
Whether the value is local or global
final
- name → String?
-
An optional name of the reference, useful for debugging
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
get(
ScopedHolder holder) → T -
Retrieves the value in the
holder
. If there isn't any, uses create to create a new value and sets it into the appropriate scope. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
override(
T create(ScopedMap scope)) → ScopedOverride< T> -
Creates a ScopedOverride for this reference using the
create
function for the value that will override -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited