resourceRef<C extends Component> static method
A resource reference property. get recovers the source resource id
from the live object it was realized into (see resourceOrigin).
Implementation
static ComponentField<C> resourceRef<C extends Component>(
String name, {
required String resourceKind,
LocalId? Function(C component, SerializeContext context)? get,
void Function(C component, LocalId id, RealizeContext context)? set,
String? doc,
String? group,
List<String> formerNames = const [],
bool transient = false,
}) => ComponentField(
ComponentPropertyDef(
name,
ComponentPropertyKind.resourceRef,
doc: doc,
group: group,
resourceKind: resourceKind,
formerNames: formerNames,
transient: transient,
),
read: get == null
? null
: (c, context) {
final id = get(c, context);
return id == null ? null : ResourceRefValue(id);
},
write: set == null
? null
: (c, v, context) {
if (v is ResourceRefValue) set(c, v.id, context);
},
);