initialDataFromAncestor<D, DAnc> method
InitialData<D>
initialDataFromAncestor<D, DAnc>(
- DataStateKey<
DAnc> ancestorKey, - D initialValue(
- DAnc ancestorData,
- P payload
Creates an InitialData that produces its initial value by calling the initialValue
function with a value of type DAnc, obtained from the ancestor state identified by
ancestorKey and the payload value of this channel.
Implementation
InitialData<D> initialDataFromAncestor<D, DAnc>(
DataStateKey<DAnc> ancestorKey,
D Function(DAnc ancestorData, P payload) initialValue,
) {
return InitialData.run((transCtx) {
try {
return initialValue(
transCtx.data(ancestorKey).value,
transCtx.payloadOrThrow<P>(),
);
} catch (e) {
throw StateError('Failed to obtain inital data of type $D for '
'channel ${label != null ? '"$label" ' : ''}'
'to state $to: $e');
}
});
}